1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : calendar/class.calendar.inc.php
5 : - Modulgruppe: Calendar
6 : - Beschreibung: Klasse für Kalenderverwaltung
7 : - Version: $Id: class.calendar.inc.php,v 1.4.20.4 2008/02/19 18:35:21 commana Exp $
8 : - Autor(en): Corinna Kropf <corinna_kropf@web.de>,
9 : Michel Kraemer <michel.kraemer@mni.fh-giessen.de>
10 : Nadja Kruemmel <nadja@kruemmel.info>
11 : +---------------------------------------------------------------------------+
12 : This program is free software; you can redistribute it and/or
13 : modify it under the terms of the GNU General Public License
14 : as published by the Free Software Foundation; either version 2
15 : of the License, or any later version.
16 : +---------------------------------------------------------------------------+
17 : This program is distributed in the hope that it will be useful,
18 : but WITHOUT ANY WARRANTY; without even the implied warranty of
19 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 : GNU General Public License for more details.
21 : You should have received a copy of the GNU General Public License
22 : along with this program; if not, write to the Free Software
23 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 : +--------------------------------------------------------------------------*/
25 : /** relativer Pfad zum Root des Portals */
26 : if (!defined("PATH_TO_ROOT")) define("PATH_TO_ROOT", "../../");
27 : require_once (PATH_TO_ROOT."calendar/classes/class.template.inc.php");
28 : require_once (PATH_TO_ROOT."calendar/classes/export/class.database.inc.php");
29 : require_once (PATH_TO_ROOT."messaging/classes/class.messaging.inc.php");
30 : require_once (PATH_TO_ROOT."calendar/classes/import/gcalendar/class.gcalendar.inc.php");
31 : /**
32 : * Klasse zur Verwaltung des Kalenders
33 : * @package eStudy.Calendar
34 : * @author Corinna Kropf <corinna_kropf@web.de>
35 : * @author Michel Kraemer <michel.kraemer@mni.fh-giessen.de>
36 : * @author Nadja Kruemmel <nadja@kruemmel.info>
37 : * @version $Id: class.calendar.inc.php,v 1.4.20.4 2008/02/19 18:35:21 commana Exp $
38 : */
39 : class Calendar {
40 : private $templates = array();
41 : private $a_monthnames = array();
42 : private $a_daynames = array();
43 : private $currentDate = array();
44 :
45 : private $db;
46 : private $gcal;
47 : private $gcalEvents;
48 :
49 : private $username = NULL;
50 : private $passwd = NULL;
51 :
52 : /**
53 : * Konstruktor
54 : */
55 : public function __construct() {
56 14 : if(isset ($_POST['username'])) {
57 0 : $_SESSION['googleUser'] = $_POST['username'];
58 0 : }
59 14 : if(isset($_SESSION['googleUser'])){
60 0 : $this->username = $_SESSION['googleUser'];
61 0 : }
62 14 : if(isset ($_POST['password'])) {
63 0 : $_SESSION['googlePasswd'] = $_POST['password'];
64 0 : }
65 14 : if(isset($_SESSION['googlePasswd'])) {
66 0 : $this->passwd = $_SESSION['googlePasswd'];
67 0 : }
68 :
69 14 : $this->db = new Database( $_SESSION['userid'] );
70 14 : if(($this->username != NULL) && ($this->passwd != NULL)) {
71 : try {
72 0 : $this->gcal = new Import_GCalendar($this->username,$this->passwd);
73 0 : $this->gcalEvents = $this->gcal->events();
74 0 : } catch (Zend_Gdata_App_Exception $e) {
75 : echo "<div style='background-color:red; margin: 5px 0px 5px 0px; color:#FFFFFF;" .
76 : " font-weight:bold; font-size:1.2em; display:block;'>" .
77 : "Fehler: " . $e->getMessage() .
78 : "</div>";
79 : $this->username = NULL;
80 : $this->passwd = NULL;
81 : }
82 0 : }
83 :
84 14 : $this->templates = array('frame' => new Template(PATH_TO_ROOT."calendar/templates/frame.html"),
85 14 : 'calendarframe' => new Template(PATH_TO_ROOT."calendar/templates/calendarframe.html"),
86 14 : 'calendarow' => new Template(PATH_TO_ROOT."calendar/templates/calendarow.html"),
87 14 : 'calendarow_empty' => new Template(PATH_TO_ROOT."calendar/templates/calendarow_empty.html"),
88 14 : 'today' => new Template(PATH_TO_ROOT."calendar/templates/calendarow_today.html"),
89 14 : 'calendareventbox' => new Template(PATH_TO_ROOT."calendar/templates/calendareventbox.html"),
90 14 : 'calendareventboxgoogle' => new Template(PATH_TO_ROOT."calendar/templates/calendareventboxgoogle.html"),
91 14 : 'calendareditevent' => new Template(PATH_TO_ROOT."calendar/templates/calendareditevent.html"),
92 14 : 'cancelevent' => new Template(PATH_TO_ROOT."calendar/templates/cancelevent.html"),
93 14 : 'newcalendarentry' => new Template(PATH_TO_ROOT."calendar/templates/newcalendarentry.html"),
94 14 : 'eventAcceptanceCancellation' => new Template(PATH_TO_ROOT."calendar/templates/eventAcceptanceCancellation.html"));
95 14 : global $navpath;
96 14 : $navpath = 'Kalender';
97 14 : $this->a_monthnames = array(1 => 'Januar', 2 => 'Februar', 3 => 'März', 4 => 'April', 5 => 'Mai', 6 => 'Juni', 7 => 'Juli', 8 => 'August', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Dezember');
98 14 : $this->a_daynames = array(1 => 'Montag', 2 => 'Dienstag', 3 => 'Mittwoch', 4 => 'Donnerstag', 5 => 'Freitag', 6 => 'Samstag', 7 => 'Sonntag');
99 14 : global $a_current;
100 14 : $a_current = array('date' => Output::echoDate("d.m.Y"), 'day' => intval(Output::echoDate("d")),
101 14 : 'month' => intval(Output::echoDate("m")), 'year' => intval(Output::echoDate("Y")), 'kw' => date("W", mktime(0, 0, 0, intval(Output::echoDate("m")), intval(Output::echoDate("d")), intval(Output::echoDate("Y")))));
102 14 : }
103 :
104 : private function getAddEventString( $thisday, $month, $year ) {
105 2 : return "<a href='calendar.php?action=newcevent&day=$thisday&month=$month&year=$year'>(neu)</a>";
106 : }
107 :
108 : /**
109 : * Erzeugt den Link zum Anlegen eines neuen Termins, welcher direkt in
110 : * einem Kalenderfeld angezeigt wird
111 : *
112 : * @param Integer $day
113 : * @param Integer $month
114 : * @param Integer $year
115 : * @return unknown
116 : */
117 : private function addEventLink( $thisday, $month, $year, $a_current ) {
118 2 : $isYearInFuture = $year > $a_current['year'];
119 2 : $isCurrentYear = $year == $a_current['year'];
120 2 : $isMonthInFuture = $month > $a_current['month'];
121 2 : $isCurrentMonth = $month == $a_current['month'];
122 2 : $isDayInFuture = $thisday >= $a_current['day'];
123 :
124 2 : $newevent = "<span class='add'>";
125 2 : if ( $isYearInFuture ) {
126 2 : $newevent .= $this->getAddEventString( $thisday, $month, $year );
127 2 : } else if ( $isCurrentYear ) {
128 0 : if ( $isMonthInFuture ) {
129 0 : $newevent .= $this->getAddEventString( $thisday, $month, $year );
130 0 : } else if ( $isCurrentMonth ) {
131 0 : if ( $isDayInFuture ) {
132 0 : $newevent .= $this->getAddEventString( $thisday, $a_current['month'], $a_current['year'] );
133 0 : }
134 0 : }
135 0 : }
136 2 : $newevent .= "</span>\n";
137 2 : return $newevent;
138 : }
139 :
140 : /**
141 : * Termin event formatiert darstellen, Rueckgabe ueber &events
142 : * @access private
143 : * @param event Daten des anzuzeigenden Termins
144 : * @param &events Pointer fuer die Rueckgabe der HTML-Elemente als String
145 : * @param month Monat in dem der Termin liegt
146 : * @param year Jahr in dem der Termin liegt
147 : */
148 : private function showEventList($event, &$events, $month, $year) {
149 0 : $err = null;
150 0 : $time = "";
151 0 : if ($event['wholetime'] == "0") {
152 0 : $time = " - ".substr($event['eventtime'], 11, 2) .":".substr($event['eventtime'], 14, 2);
153 0 : }
154 0 : $optshow = '';
155 0 : $optedit = '';
156 0 : $kindOfEvent = "";
157 0 : $groupColor = '#ffffff';
158 0 : $groupID = -1;
159 0 : if (isset($event['coursesID'])) {
160 0 : $optshow = '&coursesID='.Data::toHTML($event['coursesID']);
161 0 : $optedit = '&kindOfEvent=course&groupID='.Data::toHTML($event['coursesID']);
162 0 : $coursename = "hellblau";
163 0 : if (isset($event['Name'])) {
164 0 : $coursename = Data::toHTML($event['Name']);
165 0 : }
166 0 : $groupColor = "#".Functions::getColor($coursename, Data::toHTML($event['coursesID']));
167 0 : $err = $this->checkEventRights($event['eventid'], "course");
168 0 : $kindOfEvent = "course";
169 0 : $groupID = Data::toHTML($event['coursesID']);
170 0 : }
171 0 : if (isset($event['teamsID'])) {
172 0 : $optshow = '&teamsID='.Data::toHTML($event['teamsID']);
173 0 : $optedit = '&kindOfEvent=team&groupID='.Data::toHTML($event['teamsID']);
174 0 : $groupColor = "#".Functions::getColor($event['name'], Data::toHTML($event['teamsID']));
175 0 : $err = $this->checkEventRights(Data::toHTML($event['eventid']), "team");
176 0 : $kindOfEvent = "team";
177 0 : $groupID = Data::toHTML($event['teamsID']);
178 0 : }
179 0 : if(array_key_exists('googleEventCount', $event)){
180 0 : $events.= "<div style=\"display:block;padding-top:5%;padding:4px;background-color:$groupColor;border-top:1px solid #000\">"."<a href=\"#\" onclick=\"window.open('showevent.php?event=" . Data::toHTML($event['eventid']) . "&googleEvent=" . DATA::toHTML($event['googleEventCount']) . $optshow."',
181 0 : 'show_event','width=400,height=494,scrollbars=yes,menubar=no,toolbar=no,statusbar=no,resizable=yes')\""."title=\"Termin anzeigen\" style=\"color: #000000;\">";
182 0 : } else {
183 0 : $events.= "<div style=\"display:block;padding-top:5%;padding:4px;background-color:$groupColor;border-top:1px solid #000\">"."<a href=\"#\" onclick=\"window.open('showevent.php?event=" . Data::toHTML($event['eventid']) . $optshow."',
184 0 : 'show_event','width=400,height=494,scrollbars=yes,menubar=no,toolbar=no,statusbar=no,resizable=yes')\""."title=\"Termin anzeigen\" style=\"color: #000000;\">";
185 : }
186 : // Zeit nur anzeigen, wenn kein ganztaegiger Termin
187 0 : if (Data::toHTML($event['wholetime']) == 0) $events.= Functions::getTimeAsString(Data::toHTML($event['eventtime'])) ."<br />";
188 0 : $events.= Data::toHTML($event['eventsubject']) ."</a>";
189 0 : $iconsDivOpened = false;
190 0 : if (!isset($err)) {
191 0 : if($event['eventid'] == "Google"){
192 : //Google Termin wird als solcher gekennzeichnet
193 0 : $events.= "<br/>"."<div style=\"text-align:left;\">"."(Google Termin)";
194 0 : }else {
195 0 : $events.= "<br/>"."<div style=\"text-align:right\">"."<a href=\"calendar.php?action=edit&eventid=".Data::toHTML($event['eventid'])."&month=$month&year=$year$optedit\" title=\"Termin bearbeiten\">".Output::getIcon('icon_edit', 'Termin bearbeiten') ."</a>"."<a href=\"#\" onclick=\"javascript:deleteOK(".Data::toHTML($event['eventid']).", '$kindOfEvent', $groupID);\" title=\"Termin löschen\">".Output::getIcon('icon_delete', 'Termin l�schen') ."</a>";
196 0 : $iconsDivOpened = true;
197 : }
198 0 : }
199 : // Admins muessen die Ack/Cancel-Links nicht sehen
200 : // => Bestaetigunglink nur fuer Team-/Kurs-Mitglieder anzeigen
201 0 : if ($_SESSION['usergroup'] != ADMIN && (!isset($event['facultative']) || Data::toHTML($event['facultative']) == 0) && (isset($event['coursesID']) || Data::toHTML(isset($event['teamsID'])))) {
202 0 : if (!$iconsDivOpened) {
203 0 : $events.= "<div style=\"text-align:right\">";
204 0 : $iconsDivOpened = true;
205 0 : }
206 0 : $result = mysql_query("SELECT ack FROM calendar_acknowledgement "."WHERE eventID='".Data::toMysql($event['eventid']) ."' AND userID='".Data::toMysql($_SESSION['userid'])."'");
207 0 : $ack = -1;
208 0 : if ($result !== FALSE && mysql_num_rows($result) != 0) {
209 0 : $e = mysql_fetch_array($result);
210 0 : $ack = $e['ack'];
211 0 : }
212 0 : if ($ack == -1 || $ack == 0) {
213 0 : $events.= "<a href=\"javascript:ackOK(".Data::toHTML($event['eventid']).");\" title=\"Termin bestätigen\">".Output::getIcon('icon_check', 'Termin bestätigen') ."</a>";
214 0 : }
215 0 : if ($ack == -1 || $ack == 1) {
216 0 : $events.= "<a href=\"calendar.php?action=cancelEvent&eventid=".Data::toHTML($event['eventid'])."\" title=\"Termin absagen\">".Output::getIcon('icon_banned', 'Termin absagen') ."</a>";
217 0 : }
218 0 : }
219 : // Zu- und Absagen anzeigen
220 0 : if ($kindOfEvent == "course" && $event['coursesID'] != 0 && (!isset($event['facultative']) || Data::toHTML($event['facultative']) == 0)) {
221 0 : $events.= "<a href=\"calendar.php?action=eventAcceptanceCancellationCourse&eventid=".Data::toHTML($event['eventid'])."\" title=\"Zu- und Absagenlisten\">".Output::getIcon('icon_forum', 'Zu- und Absagen listen') ."</a>";
222 0 : } else if ($kindOfEvent == "team" && (!isset($event['facultative']) || Data::toHTML($event['facultative']) == 0)) {
223 0 : $events.= "<a href=\"calendar.php?action=eventAcceptanceCancellationTeam&eventid=".Data::toHTML($event['eventid'])."\" title=\"Zu- und Absagenlisten\">".Output::getIcon('icon_forum', 'Zu- und Absagen listen') ."</a>";
224 0 : }
225 0 : if ($iconsDivOpened) {
226 0 : $events.= "</div>";
227 0 : }
228 0 : $events.= "</div>";
229 0 : }
230 : /**
231 : * Liefert die Anzeige des nächsten Termins zurück
232 : * @access private
233 : * @param a_current
234 : * @return HTML-Code für die Anzeige des nächsten Termins
235 : */
236 : private function showEventBox($a_current) {
237 2 : $eventbox = '';
238 2 : $armageddon['year'] = 9999;
239 2 : $armageddon['month'] = 12;
240 2 : $armageddon['day'] = 31;
241 2 : $nextevents = $this->getFilteredEvents($a_current, $armageddon, true);
242 2 : if(($this->username != NULL) && ($this->passwd != NULL)) {
243 :
244 0 : $temp_a_current = $a_current;
245 0 : $temp_a_current['day'] = NULL;
246 0 : $nextevents = $this->googleToA_events($nextevents, $this->gcalEvents, $temp_a_current, $armageddon);
247 0 : }
248 2 : if (count($nextevents) > 0) {
249 : //find the next event
250 0 : $currenttime = strtotime($a_current['year']."-".$a_current['month']."-".$a_current['day']." ".date("H:m"));
251 0 : $mintime = 0x7FFFFFFF;
252 0 : $calendar = array();
253 0 : foreach($nextevents as $nextkey => $dayevents) {
254 0 : foreach($dayevents as $daykey => $event) {
255 0 : if (strtotime($event['eventtime']) < $mintime && strtotime($event['eventtime']) >= $currenttime) {
256 0 : $mintime = strtotime($event['eventtime']);
257 0 : $calendar = $event;
258 0 : }
259 0 : }
260 0 : }
261 0 : if (!empty($calendar)) {
262 0 : $optshow = '';
263 0 : $groupColor = '#ffffff';
264 0 : if (isset($calendar['coursesID'])) {
265 0 : $optshow = '&coursesID='.$calendar['coursesID'];
266 0 : $coursename = "hellblau"; //stimmt sogar!
267 0 : if (isset($calendar['Name'])) {
268 0 : $coursename = $calendar['Name'];
269 0 : }
270 0 : $groupColor = "#".Functions::getColor($coursename, $calendar['coursesID']);
271 0 : }
272 0 : if (isset($calendar['teamsID'])) {
273 0 : $optshow = '&teamsID='.$calendar['teamsID'];
274 0 : $groupColor = "#".Functions::getColor($calendar['name'], $calendar['teamsID']);
275 0 : }
276 0 : $date = Functions::getDateAsString($calendar['eventtime']);
277 0 : if ($calendar['wholetime'] == 0) {
278 0 : $date.= " - ".substr($calendar['eventtime'], 11, 5);
279 0 : }
280 0 : $calendar['eventtime'] = $date;
281 0 : $calendar['eventsubject'] = Data::toHTML($calendar['eventsubject']);
282 0 : if(array_key_exists('googleEventCount', $calendar))
283 0 : eval($this->templates['calendareventboxgoogle']->GetTemplate('eventbox'));
284 : else
285 0 : eval($this->templates['calendareventbox']->GetTemplate('eventbox'));
286 :
287 :
288 0 : }
289 0 : }
290 2 : return $eventbox;
291 : }
292 : /**
293 : * Vergleich zwei Termine (siehe ::usort())
294 : * @access private
295 : * @param $a event der erste Termin
296 : * @param $b event der zweite Termin
297 : * @return -1, wenn der erste Termin vor dem zweiten liegt,
298 : * 0, wenn beide zur gleichen Zeit stattfinden und 1 wenn der
299 : * erste Termin hinter dem zweiten liegt.
300 : */
301 : private function compareEvent($a, $b) {
302 : //Google liefert Array in Array, somit findet eStudy 'eventtime' nicht.
303 : //Wenn dies der Fall ist, wird das erste Array extrahiert.
304 0 : if(!array_key_exists('eventtime',$a)) {
305 0 : $a = $a[0];
306 0 : }
307 0 : if(!array_key_exists('eventtime',$b)) {
308 0 : $b = $b[0];
309 0 : }
310 0 : $ta = strtotime($a['eventtime']);
311 0 : $tb = strtotime($b['eventtime']);
312 0 : return ($ta > $tb ? 1 : ($ta < $tb ? -1 : 0));
313 : }
314 : /**
315 : * Zeigt den Link zum Editieren von Gruppenzeiten (je nachdem, ob
316 : * der Benutzer die Rechte dazu hat)
317 : * @access private
318 : */
319 : private function showEditGroupTimesLink() {
320 : //Gruppenzeiten editieren
321 2 : $editgrouptimes = ' ';
322 2 : if ($_SESSION['usergroup'] == ADMIN || $_SESSION['usergroup'] == DOZENT) {
323 : //Admin und Dozent darf die Zeiten des Kurses editieren
324 0 : if (isset($_SESSION['course']) && $_SESSION['course'] != 0) {
325 0 : $editgrouptimes = "<a href='grouptimesorganisation.php?"."groupID=".$_SESSION['course']."&grouptype=0'>Gruppenzeiten editieren</a>";
326 0 : }
327 2 : } else if (isset($_SESSION['teamID'])) {
328 : //Benutzer muss die Rechte haben, den Team-Kalender zu
329 : //editieren
330 0 : $sql = "SELECT editCalendar FROM user_team WHERE "."user_id= '".Data::toMysql($_SESSION['userid']) ."' "."AND team_id = '".Data::toMysql($_SESSION['teamID']) ."'";
331 0 : $sql_result = mysql_query($sql);
332 0 : if ($sql_result !== FALSE) {
333 0 : $row = mysql_fetch_array($sql_result);
334 0 : if ($row['editCalendar'] == 1) {
335 0 : $editgrouptimes = "<a href='grouptimesorganisation.php?"."groupID=".$_SESSION['teamID']."&grouptype=1'>Gruppenzeiten editieren</a>";
336 0 : }
337 0 : }
338 0 : }
339 : //Hilfetexte
340 2 : if (!empty($editgrouptimes) && $editgrouptimes != " ") {
341 0 : $editgrouptimes.= " ".Utilities::helpCode(130203);
342 0 : }
343 2 : return $editgrouptimes;
344 : }
345 : /**
346 : * Kalender erstellen und anzeigen
347 : * @access public
348 : * @param a_current
349 : * @param month anzuzeigender Monat
350 : * @param year Jahr zum Monat
351 : */
352 : public function showCalendar($a_current, $month, $year) {
353 1 : if (empty($month)) $month = $a_current['month'];
354 1 : $month = intval($month);
355 1 : if (empty($year)) $year = $a_current['year'];
356 1 : $year = intval($year);
357 1 : $month_name = $this->a_monthnames[intval($month) ];
358 1 : $gotoyearform = ' <p class="pForm"><select name="year" class="tbselect">';
359 1 : for ($i = $a_current['year']-25 ; $i <= $a_current['year']+25 ; $i++) {
360 1 : $gotoyearform.= '<option value="'.$i.'"'.($i == $year ? ' selected="selected"' : '') .'>'.$i.'</option>';
361 1 : }
362 1 : $gotoyearform.= '</select></p>';
363 1 : $gotomonthorkwform = '<p class="pForm"><select name="month" class="tbselect">';
364 1 : for ($i = 1 ; $i <= 12 ; $i++) {
365 1 : $gotomonthorkwform.= '<option value="'.$i.'"'.($i == $month ? ' selected="selected"' : '') .'>'.$this->a_monthnames[$i].'</option>';
366 1 : }
367 1 : $gotomonthorkwform.= '</select></p>';
368 1 : $firstday = intval(Output::echoDate('w', mktime(0, 0, 0, $month, 1, $year)));
369 1 : if ($firstday == 0) $firstday = 7;
370 : // Find last day of month
371 1 : $lastday = 28;
372 1 : while (checkdate($month, $lastday, $year)) {
373 1 : $lastday++;
374 1 : }
375 1 : $lastday--;
376 1 : $nextmonth = $month+1;
377 1 : if ($nextmonth == 13) {
378 0 : $nextmonth = 1;
379 0 : $nextyear = $year+1;
380 0 : } else {
381 1 : $nextyear = $year;
382 : }
383 1 : $lastmonth = $month-1;
384 1 : if ($lastmonth == 0) {
385 1 : $lastmonth = 12;
386 1 : $lastyear = $year-1;
387 1 : } else {
388 0 : $lastyear = $year;
389 : }
390 : // Termine holen
391 1 : $first_day = array('year' => $year, 'month' => $month, 'day' => '01');
392 1 : $last_day = array('year' => $year, 'month' => $month, 'day' => $lastday);
393 1 : $a_events = $this->getFilteredEvents($first_day, $last_day, true);
394 :
395 : // GoogleCalendar
396 : //all events from google and eStudy now in $a_events
397 1 : if(($this->username != NULL) && ($this->passwd != NULL)) {
398 0 : $temp_first_day = $first_day;
399 0 : $temp_first_day['day'] = NULL;
400 0 : $a_events = $this->googleToA_events($a_events, $this->gcalEvents, $temp_first_day, NULL);
401 0 : }
402 :
403 : // Terminbox erzeugen
404 1 : $eventbox = $this->showEventBox($a_current);
405 1 : $boxcount = $lastday+$firstday-1;
406 1 : if ($boxcount%7 > 0) {
407 1 : $boxcount+= 7-($boxcount%7);
408 1 : }
409 1 : $calendar = '<tr>';
410 1 : for ($i = 1 ; $i <= $boxcount ; $i++) {
411 1 : $events = '';
412 1 : if (($i < $firstday) || ($i >= $lastday+$firstday)) {
413 1 : eval($this->templates['calendarow_empty']->GetTemplate('calendar'));
414 1 : } else {
415 1 : $thisday = ($i+1) -$firstday;
416 1 : if (isset($a_events[$thisday-1])) {
417 0 : $dayevents = $a_events[$thisday-1];
418 0 : usort($dayevents, array("Calendar", "compareEvent"));
419 0 : foreach($dayevents AS $event) {
420 0 : $this->showEventList($event, $events, $month, $year);
421 0 : }
422 0 : }
423 1 : if (!strcmp(Output::echoDate("d.m.Y"), sprintf('%02d.%02d.%04d', $thisday, $month, $year))) {
424 0 : $style['specialfont'] = "<span style='color: #dd0000;'><em>";
425 0 : $style['specialfontend'] = "</em></span>";
426 0 : } else {
427 1 : $style['specialfont'] = "";
428 1 : $style['specialfontend'] = "";
429 : }
430 :
431 :
432 : // eval($this->templates['calendarow']->GetTemplate('calendar'));
433 : // Dies ist noch der alte Template-Aufruf, der nicht zwischen aktuellem und
434 : // beliebigem Tag unterscheidet.
435 :
436 1 : $newevent = $this->addEventLink( $thisday, $month, $year, $a_current );
437 :
438 : /**
439 : * Aktuelles Datum farbig hervorheben
440 : *
441 : * Hier folgt die Überprüfung, welches Template verwendet wird.
442 : * Stimmt der Kalendertag mit dem aktuellen Systemtag in Tag, Monat und Jahr
443 : * überein, wird an Stelle des 'calendarow'-Templates das 'today'
444 : * Template verwendet, welches den Tag farbig darstellt.
445 : */
446 1 : if (($thisday == $a_current['day'])&&($month == $a_current['month'])&&($year == $a_current['year']))
447 1 : {
448 0 : eval($this->templates['today']->GetTemplate('calendar'));
449 0 : }
450 : else
451 : {
452 1 : eval($this->templates['calendarow']->GetTemplate('calendar'));
453 : }
454 : // Ende der Überprüfung für farbige Hervorhebung
455 :
456 : }
457 1 : if ($i%7 == 0) {
458 1 : $kw = date("W", mktime(0, 0, 0, $month, $thisday, $year));
459 1 : $yearOfKW = $year;
460 1 : if($kw==53)
461 1 : $yearOfKW = date("Y", mktime(0, 0, 0, 1, 1, $year-1));
462 1 : $calendar.= "<td class='calendarEntry' style='text-align:center;vertcal-align:middle'>"."<a href='calendar.php?action=showWeek&kw=$kw&year=$yearOfKW&a_current=$a_current'>"."<span style='color: #000000;'>$kw</span>"."</a>"."</td>";
463 1 : $calendar.= "</tr>\n<tr>";
464 1 : }
465 1 : }
466 1 : $calendar.= "<td></td></tr>\n";
467 1 : $editgrouptimes = $this->showEditGroupTimesLink();
468 1 : $todayLink = "calendar.php?month=$a_current[month]&year=$a_current[year]";
469 1 : $showKwOnMonth = "<td class='calendarHead' style='width:10%'>KW</td>";
470 1 : $previous['link'] = "calendar.php?month=$lastmonth&year=$lastyear";
471 1 : $previous['title'] = "vorheriger Monat";
472 1 : $next['link'] = "calendar.php?month=$nextmonth&year=$nextyear";
473 1 : $next['title'] = "nächster Monat";
474 1 : $currentView = $month_name." ".$year;
475 1 : $go_action = "calendar.php";
476 :
477 1 : $icalLink = $this->db->iCalendarURL();
478 :
479 1 : eval($this->templates['calendarframe']->GetTemplate());
480 1 : eval($this->templates['frame']->GetTemplate());
481 1 : }
482 : /**
483 : * @access private
484 : * @return Liste der Kurse, in denen der User Mitglied ist
485 : */
486 : private function getUsersCourses() {
487 2 : if ($_SESSION['usergroup'] == ADMIN) {
488 : //admin sieht alle Termine aus allen Kursen
489 0 : $sql = "SELECT ID, ShortName FROM courses";
490 0 : $courses = mysql_query($sql);
491 0 : $error = mysql_error();
492 0 : if($error) {
493 0 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
494 0 : Output::errorMessage('Folgende Fehler sind aufgetreten:<br/>'.$error.'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
495 0 : echo "</table><br/><br/>";
496 0 : }
497 : else
498 0 : return $courses;
499 0 : } else {
500 : $sql = "SELECT c.courseID as ID, courses.ShortName FROM user_course c, user u, courses
501 : WHERE c.userID=u.ID
502 2 : AND u.ID=".Data::toMysql($_SESSION['userid'])." AND c.courseID=courses.ID
503 2 : GROUP BY c.courseID";
504 2 : $courses = mysql_query($sql);
505 2 : $error = mysql_error();
506 2 : if($error) {
507 2 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
508 2 : Output::errorMessage('Folgende Fehler sind aufgetreten:<br/>'.$error.'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
509 2 : echo "</table><br/><br/>";
510 2 : }
511 : else
512 0 : return $courses;
513 : }
514 2 : }
515 : /**
516 : * @access private
517 : * @return Liste der Teams, in denen der User Mitglied ist
518 : */
519 : private function getUsersTeams() {
520 2 : if ($_SESSION['usergroup'] == ADMIN) {
521 : //admin sieht alle Termine aus allen Teams
522 0 : $sql = "SELECT id as ID, name FROM teams";
523 0 : $teams = mysql_query($sql);
524 0 : $error = mysql_error();
525 0 : if($error) {
526 0 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
527 0 : Output::errorMessage('Folgende Fehler sind aufgetreten:<br/>'.$error.'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
528 0 : echo "</table><br/><br/>";
529 0 : }
530 : else
531 0 : return $teams;
532 0 : } else {
533 : $sql = "SELECT t.team_id AS ID, teams.name FROM user_team t, user u, teams
534 : WHERE t.user_id=u.ID
535 2 : AND u.ID=".Data::toMysql($_SESSION['userid'])." AND t.team_id=teams.id
536 2 : GROUP BY t.team_id";
537 2 : $teams = mysql_query($sql);
538 2 : $error = mysql_error();
539 2 : if($error) {
540 2 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
541 2 : Output::errorMessage('Folgende Fehler sind aufgetreten:<br/>'.$error.'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
542 2 : echo "</table><br/><br/>";
543 2 : }
544 : else
545 0 : return $teams;
546 : }
547 2 : }
548 : /**
549 : * Alle fuer den User sichtbaren Events auslesen, die innerhalb der gegebenen Zeitspanne liegen
550 : * @access public
551 : * @param dateOfFirstDay
552 : * @param numberOfDays
553 : */
554 : public function getAllEventsOfUser($dateOfFirstDay, $numberOfDays) {
555 0 : if ($numberOfDays < 1) return;
556 0 : if (isset($_SESSION['calendar_filter'])) $calendarFilterOptions = $_SESSION['calendar_filter'];
557 0 : $_SESSION['calendar_filter'] = 'ufct'; //alle Arten von Events
558 0 : $firstday = array('year' => substr($dateOfFirstDay, 0, 4), 'month' => substr($dateOfFirstDay, 5, 2), 'day' => substr($dateOfFirstDay, 8, 2));
559 0 : $timestampLastday = mktime(0, 0, 0, $firstday['month'], $firstday['day']+$numberOfDays-1, $firstday['year']);
560 0 : $lastday = array('year' => date("Y", $timestampLastday), 'month' => date("m", $timestampLastday), 'day' => date("d", $timestampLastday));
561 0 : $a_events = $this->getFilteredEvents($firstday, $lastday, false);
562 :
563 : //Google Termine werden auch im Foyer angezeigt
564 0 : if(($this->username != NULL) && ($this->passwd != NULL)) {
565 0 : $a_events = $this->googleToA_events($a_events, $this->gcalEvents, $firstday, $lastday);
566 0 : }
567 0 : $allEvents = array();
568 0 : foreach($a_events AS $event) {
569 : // Rechte prüfen und Event zum Ergebnis dazufügen
570 0 : $event['canEditEvent'] = 0;
571 : // Admin darf alle Termine editieren
572 0 : if ($_SESSION['usergroup'] == ADMIN) {
573 0 : $event['canEditEvent'] = 1;
574 0 : } else {
575 0 : if (isset($event['userID']) && $event['userID'] == $_SESSION['userid']) { // persönlicher Termin
576 0 : $event['canEditEvent'] = 1;
577 0 : }
578 0 : if (isset($event['coursesID']) && $event['coursesID'] > 0 && $_SESSION['usergroup'] == DOZENT && $event['coursesID'] == $_SESSION['course']) // Kurstermin
579 0 : {
580 0 : $event['canEditEvent'] = 1;
581 0 : }
582 0 : if (isset($event['teamsID'])) { // Teamtermin
583 0 : $sql = "SELECT ut.editCalendar FROM calendar_teams ct, user_team ut"." WHERE ct.eventID='".Data::toMysql($event['eventid'])."'"." AND ct.teamsID='".Data::toMysql($event['teamsID'])."'"." AND ct.teamsID = ut.team_id"." AND ut.user_id='".Data::toMysql($_SESSION['userid'])."'";
584 0 : $r_res = mysql_query($sql);
585 0 : $event['canEditEvent'] = Data::toHTML(mysql_result($r_res, 0));
586 0 : }
587 : }
588 : // einfach iterierbares Array verwenden!
589 0 : $allEvents[] = $event;
590 0 : }
591 0 : if (isset($calendarFilterOptions)) $_SESSION['calendar_filter'] = $calendarFilterOptions;
592 0 : usort($allEvents, array("Calendar", "compareEvent"));
593 0 : return $allEvents;
594 : }
595 : /**
596 : * Nach privaten, Team, Kurs und/oder fakultativen Terminen filtern
597 : * @access private
598 : * @param firstday
599 : * @param lastday
600 : * @param orderEventsByDay Ergebnis-Array sortieren: true=nach Tag des Termins im Monat, false=iteriert
601 : * @return Array mit den Events, gefiltert nach den gegebenen Filteroptionen
602 : */
603 : private function getFilteredEvents($firstday, $lastday, $orderEventsByDay) {
604 2 : $a_events = array();
605 2 : $timeframe = " c.eventtime>='".Data::toMysql($firstday['year'])."-".Data::toMysql($firstday['month'])."-".Data::toMysql($firstday['day'])." 00:00' AND c.eventtime<='".Data::toMysql($lastday['year'])."-".Data::toMysql($lastday['month'])."-".Data::toMysql($lastday['day'])." 23:59' AND c.eventactive='1'";
606 2 : if (!isset($_SESSION['calendar_filter']) || strchr($_SESSION['calendar_filter'], 'u') !== false) {
607 : //private termine
608 2 : $r_events = Functions::forum_query("SELECT DISTINCT c.*, u.userID FROM calendar c, calendar_user u
609 2 : WHERE ".$timeframe." AND u.userID=".Data::toMysql($_SESSION['userid'])."
610 : AND c.eventid=u.eventID
611 2 : ORDER BY c.eventtime");
612 2 : $error = mysql_error();
613 2 : if($error) {
614 2 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
615 2 : Output::errorMessage('Folgende Fehler sind aufgetreten:<br/>'.$error.'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
616 2 : echo "</table><br/><br/>";
617 2 : }
618 0 : else if (mysql_num_rows($r_events) > 0) {
619 0 : while ($event = mysql_fetch_array($r_events)) {
620 0 : if ($orderEventsByDay == true) $a_events[intval(substr($event['eventtime'], 8, 2)) -1][] = $event;
621 0 : else $a_events[] = $event;
622 0 : }
623 0 : }
624 2 : }
625 2 : if (!isset($_SESSION['calendar_filter']) || strchr($_SESSION['calendar_filter'], 'f') !== false) {
626 : //Foyer-Termine
627 2 : $r_events = Functions::forum_query("SELECT DISTINCT c.*,co.coursesID FROM calendar c, calendar_courses co
628 2 : WHERE ".$timeframe." AND co.coursesID=0
629 : AND c.eventid=co.eventID
630 2 : ORDER BY c.eventtime");
631 2 : $error = mysql_error();
632 2 : if($error) {
633 0 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
634 0 : Output::errorMessage('Folgende Fehler sind aufgetreten:<br/>'.$error.'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
635 0 : echo "</table><br/><br/>";
636 0 : }
637 : else
638 2 : while ($event = mysql_fetch_array($r_events)) {
639 0 : if ($orderEventsByDay == true) $a_events[intval(substr($event['eventtime'], 8, 2)) -1][] = $event;
640 0 : else $a_events[] = $event;
641 0 : }
642 2 : }
643 2 : if (!isset($_SESSION['calendar_filter']) || strchr($_SESSION['calendar_filter'], 'c') !== false) {
644 : //kurstermine
645 2 : $courses = $this->getUsersCourses();
646 2 : if (isset($courses) && ($count = mysql_num_rows($courses)) > 0) {
647 0 : $courseIDs = "(";
648 0 : $i = 0;
649 0 : while ($course = mysql_fetch_array($courses)) {
650 0 : $courseIDs.= "'".$course['ID']."'";
651 0 : if ($i < $count-1) $courseIDs.= ", ";
652 0 : $i++;
653 0 : }
654 0 : $courseIDs.= ")";
655 0 : $r_events = Functions::forum_query("SELECT DISTINCT c.*,co.coursesID, courses.Name FROM calendar c, calendar_courses co, courses
656 0 : WHERE ".$timeframe." AND co.coursesID IN $courseIDs
657 : AND co.coursesID=courses.ID
658 : AND c.eventid=co.eventID
659 0 : ORDER BY c.eventtime");
660 0 : $error = mysql_error();
661 0 : if($error) {
662 0 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
663 0 : Output::errorMessage('Folgende Fehler sind aufgetreten:<br/>'.$error.'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
664 0 : echo "</table><br/><br/>";
665 0 : }
666 : else
667 0 : while ($event = mysql_fetch_array($r_events)) {
668 0 : if ($orderEventsByDay == true) $a_events[intval(substr($event['eventtime'], 8, 2)) -1][] = $event;
669 0 : else $a_events[] = $event;
670 0 : }
671 0 : }
672 2 : }
673 2 : if (!isset($_SESSION['calendar_filter']) || strchr($_SESSION['calendar_filter'], 't') !== false) {
674 : //teamtermine
675 2 : $teams = $this->getUsersTeams();
676 2 : if (isset($teams) && ($count = mysql_num_rows($teams)) > 0) {
677 0 : $teamIDs = "(";
678 0 : $i = 0;
679 0 : while ($team = mysql_fetch_array($teams)) {
680 0 : $teamIDs.= "'".$team['ID']."'";
681 0 : if ($i < ($count-1)) $teamIDs.= ", ";
682 0 : $i++;
683 0 : }
684 0 : $teamIDs.= ")";
685 0 : $r_events = Functions::forum_query("SELECT DISTINCT c.*,t.teamsID, teams.name FROM calendar c, calendar_teams t, teams
686 0 : WHERE ".$timeframe." AND t.teamsID IN $teamIDs
687 : AND t.teamsID=teams.id
688 : AND c.eventid=t.eventID
689 0 : ORDER BY c.eventtime");
690 0 : $error = mysql_error();
691 0 : if($error) {
692 0 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
693 0 : Output::errorMessage('Folgende Fehler sind aufgetreten:<br/>'.$error.'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
694 0 : echo "</table><br/><br/>";
695 0 : }
696 : else
697 0 : while ($event = mysql_fetch_array($r_events)) {
698 0 : if ($orderEventsByDay == true) $a_events[intval(substr($event['eventtime'], 8, 2)) -1][] = $event;
699 0 : else $a_events[] = $event;
700 0 : }
701 0 : }
702 2 : }
703 2 : return $a_events;
704 : }
705 : /**
706 : * Das Datum des Montags und des Sonntags der KW ermitteln
707 : * @access private
708 : * @param kw Kalenderwoche
709 : * @param year Jahr zur Kalenderwoche
710 : */
711 : private function kw2DaysOfWeek($kw, $year) {
712 1 : $firstDayOfYear = intval(date('w', mktime(0, 0, 0, 1, 1, $year)));
713 : // Die erste KW eines Jahres ist die mit dem ersten Donnerstag des Jahres.
714 : // Nur wenn der 1.1. oder der 31.12. ein Donnerstag ist, hat das Jahr 53 Wochen,
715 : // ansonsten ist die gegebene KW die 1. des nächsten Jahres
716 1 : if($kw == 53 && intval(date('w', mktime(0, 0, 0, 12, 31, $year))) != 4 && $firstDayOfYear != 4) {
717 0 : $kw = 1;
718 0 : $year = intval(date("Y", mktime(0,0,0,1,1,$year+1)));
719 0 : $firstdayofyear = intval(date('w', mktime(0, 0, 0, 1, 1, $year)));
720 0 : }
721 1 : if ($firstDayOfYear == 0) $firstDayOfYear = 7;
722 : // Datum des Montags der gewuenschten KW ermitteln
723 1 : $monday = mktime(0, 0, 0, 1, 1-($firstDayOfYear-1), $year);
724 1 : if($kw==1) {
725 1 : if($firstDayOfYear <=4)
726 1 : $days['dateofmonday'] = mktime(0, 0, 0, date('m', $monday), date('d', $monday) + ($kw * 7)-7, date('Y', $monday));
727 : else
728 0 : $days['dateofmonday'] = mktime(0, 0, 0, date('m', $monday), date('d', $monday) + ($kw * 7), date('Y', $monday));
729 1 : }
730 0 : else if($firstDayOfYear >= 5)
731 0 : $days['dateofmonday'] = mktime(0, 0, 0, date('m', $monday), date('d', $monday) + ($kw * 7), date('Y', $monday));
732 : else
733 0 : $days['dateofmonday'] = mktime(0, 0, 0, date('m', $monday), date('d', $monday) + ($kw * 7) - 7, date('Y', $monday));
734 : // Datum des Sonntags der gewuenschten KW ermitteln
735 1 : $days['dateofsunday'] = mktime(0, 0, 0, date('m', $days['dateofmonday']), date('d', $days['dateofmonday']) + 6 , date('Y', $days['dateofmonday']));
736 1 : $days['kw'] = $kw;
737 1 : $days['year'] = $year;
738 1 : return $days;
739 : }
740 : /**
741 : * Zeigt den Kalender fuer die ausgwaehlte Kalenderwoche an
742 : * @access public
743 : * @param a_current
744 : * @param kw
745 : * @param year
746 : */
747 : public function showWeek($a_current, $kw, $year) {
748 1 : if (empty($kw) || $kw < 1 || $kw > 53) $kw = 1;
749 1 : $kw = intval($kw);
750 1 : if (empty($year)) $year = $a_current['year'];
751 1 : $year = intval($year);
752 1 : $days = $this->kw2DaysOfWeek($kw, $year);
753 1 : $kw = $days['kw'];
754 1 : $year = $days['year'];
755 1 : $monday_day = intval(date("d", $days['dateofmonday']));
756 1 : $monday_month = intval(date("m", $days['dateofmonday']));
757 1 : $monday_year = intval(date("Y", $days['dateofmonday']));
758 1 : $sunday_day = intval(date("d", $days['dateofsunday']));
759 1 : $sunday_month = intval(date("m", $days['dateofsunday']));
760 1 : $sunday_year = intval(date("Y", $days['dateofsunday']));
761 1 : $sunday_dayOfWeek = date("w", $days['dateofsunday']);
762 : // ein Jahr hat 53 Wochen, wenn es mit einem Donnerstag beginnt oder endet
763 1 : $numberOfKWs = 52;
764 1 : if($sunday_day == 3 || $sunday_day == 4) {
765 0 : $numberOfKWs = 53;
766 0 : }
767 1 : $month_name = $this->a_monthnames[intval($monday_month)];
768 1 : $monthLink = "<a href='calendar.php?month=$monday_month&year=$monday_year' title='Monat anzeigen'>".$month_name;
769 1 : if(!($monday_day > $sunday_day && $monday_year == $sunday_year))
770 1 : $monthLink .= " ".$monday_year;
771 1 : $monthLink .= "</a>";
772 : // Auswahlboxen für KW + Jahr
773 1 : $gotoyearform = ' <p class="pForm"><select name="year" class="tbselect">';
774 1 : for ($i = $a_current['year']-25 ; $i <= $a_current['year']+25 ; $i++) {
775 1 : $gotoyearform.= '<option value="'.$i.'"'.($i == $year ? ' selected="selected"' : '') .'>'.$i.'</option>';
776 1 : }
777 1 : $gotoyearform.= '</select></p>';
778 1 : $gotomonthorkwform = '<p class="pForm"><select name="kw" class="tbselect">';
779 1 : for ($i = 1 ; $i <= 53 ; $i++) {
780 1 : $gotomonthorkwform.= '<option value="'.$i.'"'.($i == $kw ? ' selected="selected"' : '') .'> KW '.$i.'</option>';
781 1 : }
782 1 : $gotomonthorkwform.= '</select></p>';
783 : // Werte der vorigen und der nächsten KW + Jahr
784 1 : $nextkw = $kw+1;
785 1 : if (($nextkw == 53 && !($sunday_day == 26 || $sunday_day == 27)) || $nextkw >= 54) {
786 0 : $nextkw = 1;
787 0 : $nextyear = $year+1;
788 0 : } else {
789 1 : $nextyear = $year;
790 : }
791 1 : $lastkw = $kw-1;
792 1 : if ($lastkw == 0) { // vorherige Woche ist der Jahresübergang
793 1 : $lastkw = 52;
794 1 : $lastyear = $monday_year;
795 1 : if($monday_day == 4) { // 1.1. ein Freitag -> angezeigte Woche: Montag ist der 4.1.
796 0 : $lastkw = 53;
797 0 : $lastyear = date("Y", mktime(0,0,0,1,1,$monday_year-1));
798 0 : }
799 1 : if($sunday_day >= 7) {
800 1 : $lastyear = date("Y", mktime(0,0,0,1,1,$monday_year-1));
801 1 : }
802 1 : } else {
803 0 : $lastyear = $monday_year;
804 : }
805 : // Find last day of month
806 1 : $lastday = 28;
807 1 : while (checkdate($monday_month, $lastday, $monday_year)) {
808 1 : $lastday++;
809 1 : }
810 1 : $lastday--;
811 : // Termine holen
812 1 : $first_day = array('year' => $monday_year, 'month' => $monday_month, 'day' => $monday_day);
813 1 : $last_day = array('year' => $sunday_year, 'month' => $sunday_month, 'day' => $sunday_day);
814 1 : $a_events = $this->getFilteredEvents($first_day, $last_day, true);
815 : // Terminbox erzeugen
816 1 : $eventbox = $this->showEventBox($a_current);
817 1 : $calendar = '<tr>';
818 1 : $thisday = $monday_day;
819 1 : $month = $monday_month;
820 1 : for ($i = 1 ; $i <= 7 ; $i++, $thisday++) {
821 1 : $events = '';
822 1 : if($sunday_day==3 && $i == (7-$sunday_day+1)) {
823 0 : $thisday = 1;
824 0 : $month = $sunday_month;
825 0 : $year = $sunday_year;
826 0 : }
827 1 : if (isset($a_events[$thisday-1])) {
828 0 : foreach($a_events[$thisday-1] AS $event) {
829 0 : $this->showEventList($event, $events, $month, $year);
830 0 : }
831 0 : }
832 1 : if (!strcmp(Output::echoDate("d.m.Y"), sprintf('%02d.%02d.%04d', $thisday, $month, $year))) {
833 0 : $style['specialfont'] = "<span style='color: #dd0000;'><em>";
834 0 : $style['specialfontend'] = "</em></span>";
835 0 : } else {
836 1 : $style['specialfont'] = "";
837 1 : $style['specialfontend'] = "";
838 : }
839 :
840 1 : $newevent = $this->addEventLink( $thisday, $month, $year, $a_current );
841 :
842 1 : eval($this->templates['calendarow']->GetTemplate('calendar'));
843 : //der nächste Tag liegt schon im nächsten Monat
844 1 : if ($thisday == $lastday) { //$sunday < 7 && $thisday == ($monday + (6-$sunday))) {
845 0 : $thisday = 0;
846 0 : $nextmonth = $monday_month+1 == 13 ? 1 : $month+1;
847 0 : $month_name = $this->a_monthnames[intval($nextmonth)];
848 0 : if($sunday_day != 31)
849 0 : $monthLink .= " / " . "<a href='calendar.php?month=$nextmonth&year=$nextyear' title='Monat anzeigen'>".$month_name." ".$nextyear."</a>";
850 0 : }
851 1 : }
852 1 : $calendar.= "</tr>\n<tr>";
853 1 : $calendar.= "<td></td></tr>\n";
854 1 : $editgrouptimes = $this->showEditGroupTimesLink();
855 1 : $todayLink = "calendar.php?action=showWeek&kw=$a_current[kw]&year=$a_current[year]";
856 1 : $showKwOnMonth = '';
857 1 : $previous['link'] = "calendar.php?action=showWeek&kw=$lastkw&year=$lastyear";
858 1 : $previous['title'] = "vorherige Woche";
859 1 : $next['link'] = "calendar.php?action=showWeek&kw=$nextkw&year=$nextyear";
860 1 : $next['title'] = "nächste Woche";
861 1 : $currentView = "KW ".$kw." - ".$monthLink;
862 1 : $go_action = "calendar.php?action=showWeek";
863 :
864 1 : $icalLink = "icalendar.php?user=" . $_SESSION['userid'] . "&token=" . $this->db->hash( $_SESSION['userid'] );
865 :
866 1 : eval($this->templates['calendarframe']->GetTemplate());
867 1 : eval($this->templates['frame']->GetTemplate());
868 1 : }
869 : /**
870 : * Zeigt Formular zum aendern des betreffenden Termins an
871 : * @access public
872 : * @param month
873 : * @param year
874 : * @param event
875 : * @param kindOfEvent
876 : * @param groupID
877 : */
878 : public function edit($month, $year, $event, $kindOfEvent, $groupID) {
879 1 : $action = "calendar.php?action=saveedit&month=$month&year=$year";
880 1 : $optionSendMessage = "";
881 1 : if (!isset($kindOfEvent)) {
882 1 : $errMsg = $this->checkEventRights($event, $kindOfEvent);
883 1 : if (!isset($errMsg)) {
884 0 : $r_calendar = mysql_query("SELECT * FROM calendar c, calendar_user u
885 0 : WHERE c.eventid = '".Data::toMysql($event)."'
886 0 : AND u.userID='".Data::toMysql($_SESSION['userid'])."'
887 0 : AND c.eventid=u.eventid");
888 0 : }
889 1 : } else {
890 0 : $errMsg = $this->checkEventRights($event, $kindOfEvent);
891 0 : $optionSendMessage = "<input type=\"checkbox\" "."name=\"changedevent[sendmessage]\ checked=\"checked\" /> Teilnehmern eine Nachricht schicken";
892 0 : if (!isset($errMsg)) {
893 0 : if ($kindOfEvent == 'course') {
894 0 : $r_calendar = mysql_query("SELECT * FROM calendar c, calendar_courses co
895 0 : WHERE c.eventid = '".Data::toMysql($event)."'
896 0 : AND co.coursesID= '".Data::toMysql($groupID)."'
897 0 : AND c.eventid=co.eventID");
898 0 : }
899 0 : if ($kindOfEvent == 'team') {
900 0 : $r_calendar = mysql_query("SELECT * FROM calendar c, calendar_teams t
901 0 : WHERE c.eventid = '".Data::toMysql($event)."'
902 0 : AND t.teamsID = '".Data::toMysql($groupID)."'
903 0 : AND c.eventid=t.eventID");
904 0 : }
905 0 : $action.= "&kindOfEvent=$kindOfEvent&groupID=$groupID";
906 0 : }
907 : }
908 1 : if (isset($errMsg)) {
909 1 : Functions::message_redirect($errMsg, "calendar.php?month=".$month."&year=".$year);
910 1 : } else {
911 0 : $calendar = mysql_fetch_array($r_calendar);
912 0 : $eventsubject = Data::toHTML($calendar['eventsubject']);
913 0 : $eventtext = Data::toHTML($calendar['eventtext']);
914 0 : if ($calendar['wholetime'] == '1') {
915 0 : $eventtime = array(0 => substr($calendar['eventtime'], 8, 2), 1 => substr($calendar['eventtime'], 5, 2), 2 => substr($calendar['eventtime'], 0, 4), 3 => "", 4 => "");
916 0 : } else {
917 0 : $eventtime = array(0 => substr($calendar['eventtime'], 8, 2), 1 => substr($calendar['eventtime'], 5, 2), 2 => substr($calendar['eventtime'], 0, 4), 3 => substr($calendar['eventtime'], 11, 2), 4 => substr($calendar['eventtime'], 14, 2));
918 : }
919 0 : $oldEventtime = $calendar['wholetime'] == 1 ? substr($calendar['eventtime'], 0, 10) : $calendar['eventtime'];
920 0 : $oldEventtime = strtr ( Data::toHTML($oldEventtime), " ", "%20" ); // W3C-Konform: keine Leerzeichen, stattdessen %20
921 0 : $action.= "&oldEventtime=$oldEventtime";
922 0 : eval($this->templates['calendareditevent']->GetTemplate());
923 : }
924 1 : }
925 : /**
926 : * Terminaenderung speichern
927 : * @access public
928 : * @param eventid ID des zu aendernden Events
929 : * @param changedevent Neue Daten des Termins
930 : * @param kindOfEvent "team" bei einem Teamtermin, "course" bei einem Kurstermin, bei privatem Termin leer
931 : * @param groupID ID der Gruppe, null bei privatem Termin
932 : */
933 : public function saveedit($eventid, $changedevent, $kindOfEvent, $groupID) {
934 1 : global $db;
935 1 : $a_errmsg = array();
936 : //Uhrzeit und Datum überprüfen
937 1 : if (!checkdate($changedevent['newmonth'], $changedevent['newday'], $changedevent['newyear'])) $a_errmsg[] = 'Sie haben ein ungültiges Datum angegeben.';
938 1 : if ($changedevent['newhour'] < 0 || $changedevent['newhour'] > 23 || $changedevent['newminute'] < 0 || $changedevent['newminute'] > 59 ) $a_errmsg[] = 'Sie haben eine ungültige Uhrzeit angegeben.';
939 1 : if (array_count_values($a_errmsg)) {
940 0 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
941 0 : Output::errorMessage('Folgende Fehler sind bei der Eingabe aufgetreten:<br/>'.Data::toHTML(implode($a_errmsg, '<br/>')) .'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
942 0 : echo "</table><br/><br/>";
943 0 : } else {
944 1 : if (!isset($changedevent['newhour']) || $changedevent['newhour'] == '') {
945 0 : $time = $changedevent['newyear']."-".$changedevent['newmonth']."-".$changedevent['newday']." 00:00:00";
946 0 : $wholetime = "1";
947 0 : } else {
948 1 : if (!isset($changedevent['newminute'])) {
949 0 : $changedevent['newminute'] = 0;
950 0 : $time = $changedevent['newyear']."-".$changedevent['newmonth']."-".$changedevent['newday']." ".$changedevent['newhour'].":00:00";
951 0 : $wholetime = "0";
952 0 : }
953 1 : $time = $changedevent['newyear']."-".$changedevent['newmonth']."-".$changedevent['newday']." ".$changedevent['newhour'].":".$changedevent['newminute'].":00";
954 1 : $wholetime = "0";
955 : }
956 1 : $r_oldEvent = mysql_query("SELECT * FROM calendar WHERE eventid='".Data::toMysql($eventid)."'");
957 1 : $oldEvent = mysql_fetch_array($r_oldEvent);
958 1 : if ($oldEvent['facultative'] == 0) {
959 : // Art des Termins
960 1 : if ($kindOfEvent == "course") {
961 0 : $sql = "SELECT * FROM calendar_frame_courses c JOIN calendar_frame cf ON cf.ID = c.frameID WHERE c.coursesID ='".Data::toMysql($groupID, false)."'";
962 1 : } else if ($kindOfEvent == "team") {
963 0 : $sql = "SELECT * FROM calendar_frame_teams c JOIN calendar_frame cf ON cf.ID = c.frameID WHERE c.teamsID = '".Data::toMysql($groupID, false)."'";
964 0 : }
965 1 : if ($kindOfEvent == "team" || $kindOfEvent == "course") {
966 0 : $resultList = $db->get_results($sql, ARRAY_A);
967 0 : if ($resultList != null) {
968 0 : for ($i = 0 ; $i < count($resultList) ; $i++) {
969 : // wenn innerhalb der gruppenzeit
970 0 : if (Calendar::inGrouptime($resultList[$i]['startday'], $resultList[$i]['endday'], $resultList[$i]['starttime'], $resultList[$i]['endtime'], $time, $wholetime)) {
971 : // alle werden auf zustimmen gesetzt
972 0 : $kindOfAck = "all";
973 0 : break;
974 : } else {
975 : // Pruefen, ob der Termin immernoch in der Gruppenzeit liegt.
976 0 : $kindOfAck = "notInGroupTime";
977 : }
978 0 : }
979 0 : }
980 0 : }
981 1 : }
982 : //Änderungen und Benachrichtigungen nur, wenn wirklich was geändert wurde
983 1 : if ($oldEvent['eventsubject'] != Data::toMysql($changedevent['newsubject']) || $oldEvent['eventtext'] != Data::toMysql($changedevent['newtext']) || $oldEvent['eventtime'] != $time || $oldEvent['wholetime'] != $wholetime) {
984 1 : Functions::forum_query("BEGIN;");
985 1 : $update_event = mysql_query("UPDATE calendar SET "."eventsubject = '".Data::toMysql($changedevent['newsubject']) ."', eventtext = '".Data::toMysql($changedevent['newtext']) ."', eventtime = '".Data::toMysql($time)."', wholetime = '".Data::toMysql($wholetime)."' "."WHERE eventid = '".Data::toMysql($eventid)."'");
986 1 : if (isset($kindOfAck)) {
987 0 : if ($kindOfAck == "notInGroupTime") {
988 0 : if ($kindOfEvent == "course") {
989 0 : $eventMembers = Calendar::getEventMembers($groupID, $kindOfEvent);
990 0 : } else if ($kindOfEvent == "team") {
991 0 : $eventMembers = Calendar::getEventMembers($groupID, $kindOfEvent);
992 0 : }
993 0 : for ($i = 0 ; $i < count($eventMembers) ; $i++) {
994 0 : $sql = ("UPDATE calendar_acknowledgement SET ack = '0', reason = 'Termin wurde verschoben. Er ist nun ausserhalb der Gruppenzeit. Er wurde deshalb abgesagt.' WHERE eventid = '".Data::toMysql($oldEvent['eventid'])."';");
995 0 : Functions::forum_query($sql);
996 0 : }
997 0 : } else if ($kindOfAck == "all") {
998 0 : if ($kindOfEvent == "course") {
999 0 : $eventMembers = Calendar::getEventMembers($_SESSION['course'], $kindOfEvent);
1000 0 : } else if ($kindOfEvent == "team") {
1001 0 : $eventMembers = Calendar::getEventMembers($_SESSION['teamID'], $kindOfEvent);
1002 0 : }
1003 0 : for ($i = 0 ; $i < count($eventMembers) ; $i++) {
1004 0 : $sql = ("UPDATE calendar_acknowledgement SET ack = '1', reason = 'Termin wurde automatisch auf akzeptiert gesetzt, da er innerhalb der Gruppenzeit liegt.' WHERE eventid = '".Data::toMysql($oldEvent['eventid'])."';");
1005 0 : Functions::forum_query($sql);
1006 0 : }
1007 0 : }
1008 0 : }
1009 1 : Functions::forum_query("COMMIT;");
1010 1 : Functions::message_redirect("Update erfolgreich", "calendar.php?month=".$changedevent['newmonth']."&year=".$changedevent['newyear']);
1011 1 : if (isset($changedevent['sendmessage']) && isset($kindOfEvent) && $kindOfEvent != '') { // dem Kurs eine Message schicken
1012 0 : $this->sendGroupMessage($kindOfEvent, $groupID, $eventid, 0, "edit", $oldEvent);
1013 0 : }
1014 1 : } else {
1015 0 : Functions::message_redirect("Keine Änderungen vorgenommen", "calendar.php?month=".$changedevent['newmonth']."&year=".$changedevent['newyear']);
1016 : }
1017 : }
1018 1 : }
1019 : /**
1020 : * Pruefe, ob der Benutzer die Rechte hat, den Kalender zu bearbeiten,
1021 : * d.h., ob es ein persönlicher Termin des Benutzers ist oder
1022 : * ob er in der Gruppe des Termins ist und die Rechte hat
1023 : * @access private
1024 : * @param id ID des Events
1025 : * @param kindOfEvent ID Eventtyp wenn es ein Gruppentermin ist
1026 : * @return Fehlermeldung, wenn ein Fehler aufgetreten ist
1027 : */
1028 : private function checkEventRights($id, $kindOfEvent) {
1029 : //der Admin darf alles
1030 2 : if ($_SESSION['usergroup'] == ADMIN) {
1031 0 : return null;
1032 : }
1033 : //jeder darf seine eigenen Termine ändern/löschen
1034 2 : if (!isset($kindOfEvent) || $kindOfEvent == null) {
1035 2 : $result = mysql_query("SELECT eventid FROM calendar_user
1036 2 : WHERE userID='".Data::toMysql($_SESSION['userid'])."'
1037 2 : AND eventID='".Data::toMysql($id)."'");
1038 2 : }
1039 : //Nur Dozenten oder "Hilfsdozenten" dürfen Gruppentermine ändern/löschen
1040 2 : if (isset($kindOfEvent) && $kindOfEvent == 'course' && $_SESSION["usergroup"] == DOZENT) {
1041 0 : $result = mysql_query("SELECT c.eventid FROM calendar c
1042 : JOIN calendar_courses cc ON c.eventid=cc.eventID
1043 : JOIN user_course uc ON uc.courseID=cc.coursesID
1044 : JOIN user ON user.ID=uc.userID
1045 0 : WHERE uc.userID='".Data::toMysql($_SESSION['userid'])."'
1046 0 : AND c.eventid='".Data::toMysql($id)."'
1047 0 : AND (uc.differentUsergroup='".Data::toMysql(DOZENT)."' OR user.usergroup='".Data::toMysql(DOZENT)."')");
1048 0 : }
1049 : //Team-Mitglieder dürfen Team-Termine ändern, wenn editCalendar==1
1050 2 : if (isset($kindOfEvent) && $kindOfEvent == 'team') {
1051 0 : $result = mysql_query("SELECT teamsID FROM calendar_teams
1052 0 : WHERE eventID='".Data::toMysql($id)."'");
1053 0 : if (mysql_num_rows($result) > 0) {
1054 0 : $tID = intval(mysql_result($result, 0));
1055 0 : $result = mysql_query("SELECT * FROM user_team
1056 0 : WHERE team_id='".Data::toMysql($tID)."'
1057 0 : AND user_id='".Data::toMysql($_SESSION['userid'])."'
1058 0 : AND editCalendar='1'");
1059 0 : }
1060 0 : }
1061 2 : if (!isset($result) || $result == null || (mysql_num_rows($result) == 0)) {
1062 1 : return "Dieser Termin existiert nicht oder Sie haben nicht genügend Rechte, um diesen Termin zu bearbeiten";
1063 : }
1064 1 : }
1065 : /**
1066 : * Termin loeschen
1067 : * @access public
1068 : * @param id ID des Events
1069 : * @param kindOfEvent "team" wenn es ein Teamtermin ist, "course" bei einem Kurstermin, sonst leer
1070 : * @param groupID ID des Teams/Kurses; null wenn es ein privater Termin ist
1071 : */
1072 : public function deleteEventID($id, $kindOfEvent, $groupID) {
1073 1 : if ($kindOfEvent == '') $errMsg = $this->checkEventRights($id, null);
1074 0 : else $errMsg = $this->checkEventRights($id, $kindOfEvent);
1075 1 : if (!isset($errMsg)) {
1076 1 : $r_oldEvent = mysql_query("SELECT * FROM calendar WHERE eventid='".Data::toMysql($id)."'");
1077 1 : $oldEvent = mysql_fetch_array($r_oldEvent);
1078 1 : $del_event = mysql_query("DELETE FROM calendar WHERE eventid = '".Data::toMysql($id) ."'");
1079 1 : $del_event = mysql_query("DELETE FROM calendar_user WHERE eventID = '".Data::toMysql($id) ."'");
1080 1 : $del_event = mysql_query("DELETE FROM calendar_teams WHERE eventID = '".Data::toMysql($id) ."'");
1081 1 : $del_event = mysql_query("DELETE FROM calendar_courses WHERE eventID = '".Data::toMysql($id) ."'");
1082 1 : $del_event = mysql_query("DELETE FROM calendar_acknowledgement WHERE eventID ='".Data::toMysql($id) ."'");
1083 1 : Functions::message_redirect("Termin wurde gelöscht", "calendar.php");
1084 1 : if (isset($kindOfEvent) && $kindOfEvent != '' && $groupID >= 0) {
1085 0 : $this->sendGroupMessage($kindOfEvent, $groupID, $id, 0, "del", $oldEvent);
1086 0 : }
1087 1 : } else {
1088 0 : Functions::message_redirect($errMsg, "calendar.php");
1089 : }
1090 1 : }
1091 : /**
1092 : * Zeigt Formular fuer die Absage eines Termins an
1093 : * @access public
1094 : * @param id ID des Termins
1095 : */
1096 : public function cancelEventId($id) {
1097 1 : $result = mysql_query("SELECT * FROM calendar WHERE eventid='".Data::toMysql($id) ."'");
1098 1 : $event = mysql_fetch_array($result);
1099 1 : $event['eventtime'] = Functions::getDateAsString($event['eventtime']);
1100 1 : eval($this->templates['cancelevent']->GetTemplate());
1101 1 : eval($this->templates['frame']->GetTemplate());
1102 1 : }
1103 : /**
1104 : * Termin absagen
1105 : * @access public
1106 : * @param id ID des Termins, fuer den die Absage erfolgt
1107 : * @param reason
1108 : */
1109 : public function do_cancelEventId($id, $reason) {
1110 1 : $result = mysql_query("SELECT ack FROM calendar_acknowledgement "."WHERE eventID='".Data::toMysql($id) ."' AND userID='".Data::toMysql($_SESSION['userid'])."'");
1111 1 : if ($result !== FALSE) {
1112 1 : if (mysql_num_rows($result) == 0) {
1113 1 : mysql_query("INSERT INTO calendar_acknowledgement (eventID,userID,"."ack, reason) VALUES ('".Data::toMysql($id) ."','".Data::toMysql($_SESSION['userid'])."',0,'".Data::toMysql($reason) ."')");
1114 1 : } else {
1115 0 : mysql_query("UPDATE calendar_acknowledgement SET ack='0', "."reason='".Data::toMysql($reason) ."' "."WHERE eventid='".Data::toMysql($id) ."' AND userID='".Data::toMysql($_SESSION['userid'])."'");
1116 : }
1117 1 : $result = mysql_query("SELECT eventtime FROM calendar WHERE "."eventid='".Data::toMysql($id) ."'");
1118 1 : $event = mysql_fetch_array($result);
1119 1 : Functions::message_redirect("Termin abgesagt", "calendar.php?month=".substr($event['eventtime'], 5, 2) ."&year=".substr($event['eventtime'], 0, 4));
1120 1 : }
1121 1 : }
1122 : /**
1123 : * Termin bestaetigen
1124 : * @access public
1125 : * @param id ID des Termins, fuer den die Bestaetigung erfolgt
1126 : */
1127 : public function do_ackEventId($id) {
1128 1 : $result = mysql_query("SELECT ack FROM calendar_acknowledgement "."WHERE eventID='".Data::toMysql($id) ."' AND userID='".Data::toMysql($_SESSION['userid'])."'");
1129 1 : if ($result !== FALSE) {
1130 1 : if (mysql_num_rows($result) == 0) {
1131 1 : mysql_query("INSERT INTO calendar_acknowledgement (eventID,userID,"."ack, reason) VALUES ('".Data::toMysql($id) ."','".Data::toMysql($_SESSION['userid'])."',1,'')");
1132 1 : } else {
1133 0 : mysql_query("UPDATE calendar_acknowledgement SET ack='1' , reason ='' "."WHERE eventid='".Data::toMysql($id) ."' AND userID='".Data::toMysql($_SESSION['userid'])."'");
1134 : }
1135 1 : $result = mysql_query("SELECT eventtime FROM calendar WHERE "."eventid='".Data::toMysql($id) ."'");
1136 1 : $event = mysql_fetch_array($result);
1137 1 : Functions::message_redirect("Termin bestätigt", "calendar.php?month=".substr($event['eventtime'], 5, 2) ."&year=".substr($event['eventtime'], 0, 4));
1138 1 : }
1139 1 : }
1140 : /**
1141 : * Zeigt Formular zum Eintragen eines neuen Termins an
1142 : * @access public
1143 : * @param day
1144 : * @param month
1145 : * @param year
1146 : * @param event
1147 : * @param navpath
1148 : */
1149 : public function newcevent($day, $month, $year, $event, $navpath) {
1150 1 : global $db;
1151 1 : $optionPrivate = "";
1152 1 : $optionCourse = "";
1153 1 : $optionTeam = "";
1154 1 : $optionSendMessage = "";
1155 : //dozenten können Kurstermine eintragen
1156 1 : if (($_SESSION['usergroup'] == DOZENT || $_SESSION['usergroup'] == ADMIN) && $_SESSION['course'] != 0) {
1157 0 : $sql = "SELECT name FROM courses WHERE ID = '".Data::toMysql($_SESSION['course']) ."'";
1158 0 : $resultList = $db->get_results($sql, ARRAY_A);
1159 0 : if ($resultList != null) {
1160 0 : $optionCourse = "<input type=\"radio\" name=\"event[kind]\" "."value=\"course\" /> Termin für Kurs: »".$resultList[0]['name']."«<br />";
1161 0 : }
1162 0 : }
1163 1 : if ($_SESSION['usergroup'] == ADMIN && $_SESSION['course'] == 0) {
1164 0 : $optionCourse = "<input type=\"radio\" name=\"event[kind]\" "."value=\"course\" /> Termin für das Foyer<br />";
1165 0 : }
1166 : // Teamtermine
1167 1 : if (isset($_SESSION['teamID'])) {
1168 0 : $userid = $_SESSION['userid'];
1169 0 : $teamid = $_SESSION['teamID'];
1170 0 : $sql = "SELECT editCalendar FROM user_team WHERE user_id= '".Data::toMysql($userid) ."' "."AND team_id = '".Data::toMysql($teamid) ."'";
1171 0 : $resultList = $db->get_results($sql, ARRAY_A);
1172 0 : if ($resultList != null) {
1173 0 : if ($resultList[0]['editCalendar'] == 1) {
1174 : // user darf termine eintragen und editieren.
1175 0 : $sql = "SELECT t.name as teamname, c.name as coursename "."FROM teams t JOIN courses c ON course_id = c.ID "."WHERE t.id = '".Data::toMysql($teamid) ."'";
1176 0 : $resultList = $db->get_results($sql, ARRAY_A);
1177 0 : if ($resultList != null) {
1178 0 : $optionTeam = "<input type=\"radio\" name=\"event[kind]\" "."value=\"team\" /> Termin für Team: »".$resultList[0]['teamname']."«<br />";
1179 0 : }
1180 0 : }
1181 0 : }
1182 0 : }
1183 1 : if ($optionTeam != "" || $optionCourse != "") {
1184 0 : $optionPrivate = "<input type=\"radio\" name=\"event[kind]\" "."value=\"user\" checked=\"checked\" /> Privater Termin<br />";
1185 0 : $optionSendMessage = "<input type=\"checkbox\" "."name=\"event[sendmessage]\" /> Teilnehmern eine Nachricht schicken";
1186 0 : }
1187 1 : $navpath = 'Neuer Kalendereintrag';
1188 1 : $event['day'] = ((isset($day)) ? $day : Output::echoDate("d"));
1189 1 : $event['month'] = ((isset($month)) ? $month : Output::echoDate("m"));
1190 1 : $event['year'] = ((isset($year)) ? $year : Output::echoDate("Y"));
1191 1 : $event['hour'] = ((isset($hour)) ? $hour : '');
1192 1 : $event['minute'] = ((isset($minute)) ? $minute : '');
1193 1 : if (!isset($event['subject'])) $event['subject'] = '';
1194 1 : if (!isset($event['text'])) $event['text'] = '';
1195 1 : if (!isset($event['facultative'])) $event['facultative'] = Data::toHTML(0);
1196 : //Hilfetexte
1197 1 : $helpFacultative = Utilities::helpCode(130201);
1198 1 : eval($this->templates['newcalendarentry']->GetTemplate());
1199 1 : eval($this->templates['frame']->GetTemplate());
1200 1 : }
1201 : /**
1202 : * Diese Methode erstellt eine Liste mit allen Personen dieses Teams und die dazugehoerigen Zu- und Absagen sowie
1203 : * falls sich der jenige nicht zurueckgemeldet hat.
1204 : * Am Ende der Methode wird das entsprechende Template aufgerufen und die Seite angezeigt.
1205 : * @access public
1206 : * @param $eventid ID zu dem die entsprechende Liste erstellt werden soll.
1207 : * @author Nadja Kruemmel <nadja@kruemmel.info>
1208 : */
1209 : public function eventAcceptanceCancellationTeam($eventid) {
1210 0 : global $navpath, $db;
1211 :
1212 0 : $sql = "SELECT DISTINCT c.*, ct.teamsID FROM calendar c JOIN calendar_teams ct ON c.eventID = ct.eventID JOIN user_team ut ON ct.teamsID = ut.team_id WHERE c.eventid = '".Data::toMysql($eventid)."'";
1213 0 : $resultList = $db->get_results($sql, ARRAY_A);
1214 0 : if ($resultList != null) {
1215 0 : $date = $resultList[0]['eventtime'];
1216 0 : if ($resultList[0]['wholetime'] == "1") {
1217 0 : $dateString = Functions::getDateAsString($date);
1218 0 : } else {
1219 0 : $dateString = Functions::getDateAsString($date) ." um ".Functions::getTimeAsString($date);
1220 : }
1221 0 : $teamID = $resultList[0]['teamsID'];
1222 0 : }
1223 0 : $sql = "SELECT DISTINCT ca.*, u.Vorname, u.nachname, u.Email "."FROM calendar_acknowledgement ca JOIN user u ON ca.userID = u.ID "."WHERE ca.eventID = '".Data::toMysql($eventid)."' AND ca.userid IN (SELECT ut.user_ID FROM calendar_teams ct JOIN user_team ut ON ct.teamsID = ut.team_id WHERE ct.eventID = '".Data::toMysql($eventid)."') "." ORDER BY u.Nachname";
1224 0 : $resultList = $db->get_results($sql, ARRAY_A);
1225 0 : $acceptanceCancellations = "";
1226 0 : if ($resultList != null) {
1227 0 : for ($i = 0 ; $i < count($resultList) ; $i++) {
1228 0 : if ($i%2 == 0) $acceptanceCancellations.= "<tr class='tableCell' valign='top'>";
1229 0 : else $acceptanceCancellations.= "<tr class='tableCellDark' valign='top'>";
1230 0 : $acceptanceCancellations.= "<td style='width: 40%;'>".Data::toHTML($resultList[$i]['nachname']).", ".Data::toHTML($resultList[$i]['Vorname'])."</td>";
1231 0 : if ($resultList[$i]['ack'] == true) {
1232 0 : $acceptanceCancellations.= "<td>Zugesagt</td><td>".Data::toHTML($resultList[$i]['reason'])."</td>";
1233 0 : } else {
1234 0 : $acceptanceCancellations.= "<td>Abgesagt</td><td>".Data::toHTML($resultList[$i]['reason'])."</td>";;
1235 : }
1236 0 : $acceptanceCancellations.= "</tr>";
1237 0 : }
1238 0 : }
1239 0 : $sql = "SELECT DISTINCT u.Id, u.Vorname, u.nachname, u.Email "."from user_team ut "."JOIN user u "."ON u.ID = ut.user_ID "."WHERE ut.team_ID = '".Data::toMysql($teamID)."' "."and u.id not in (SELECT DISTINCT userID "."FROM calendar_acknowledgement ca "."JOIN user u "."ON ca.userID = u.ID "."WHERE ca.eventID = '".Data::toMysql($eventid)."' "."and ca.userid in (select ut.user_ID from calendar_teams ct JOIN user_team ut ON ct.teamsID = ut.team_id WHERE ct.eventID = '".Data::toMysql($eventid)."' )".")";
1240 0 : $resultList = $db->get_results($sql, ARRAY_A);
1241 0 : $notAck = "";
1242 0 : if ($resultList != null) {
1243 0 : for ($i = 0 ; $i < count($resultList) ; $i++) {
1244 0 : if ($i%2 == 0) $notAck = $notAck."<tr class='tableCell' valign='top'>";
1245 0 : else $notAck = $notAck."<tr class='tableCellDark' valign='top'>";
1246 0 : $notAck = $notAck."<td style='width: 40%;'>".Data::toHTML($resultList[$i]['nachname']).", ".Data::toHTML($resultList[$i]['Vorname'])."</td>";
1247 0 : $notAck = $notAck."<td>noch keine Rückmeldung</td>";
1248 0 : $notAck = $notAck."</tr>";
1249 0 : }
1250 0 : }
1251 : //Hilfetexte
1252 0 : $helpAcceptanceCancellation = Utilities::helpCode(130202);
1253 0 : eval($this->templates['eventAcceptanceCancellation']->GetTemplate());
1254 0 : }
1255 : /**
1256 : * Diese Methode erstellt eine Liste mit allen Personen dieses Kurses und die dazugehoerigen Zu- und Absagen sowie
1257 : * falls sich der jenige nicht zurueckgemeldet hat.
1258 : * Am Ende der Methode wird das entsprechende Template aufgerufen und die Seite angezeigt.
1259 : * @access public
1260 : * @param $eventid ID zu dem die entsprechende Liste erstellt werden soll.
1261 : * @author Nadja Kruemmel <nadja@kruemmel.info>
1262 : */
1263 : public function eventAcceptanceCancellationCourse($eventid) {
1264 1 : global $navpath, $db;
1265 :
1266 1 : $sql = "SELECT DISTINCT c.*, cc.coursesID FROM calendar c JOIN calendar_courses cc ON c.eventID = cc.eventID JOIN user_course uc ON cc.coursesID=uc.courseID WHERE c.eventid = '".Data::toMysql($eventid)."'";
1267 1 : $dateString = "--";
1268 1 : $resultList = $db->get_results($sql, ARRAY_A);
1269 1 : if ($resultList != null) {
1270 0 : $date = $resultList[0]['eventtime'];
1271 0 : if ($resultList[0]['wholetime'] == "1") {
1272 0 : $dateString = Functions::getDateAsString($date);
1273 0 : } else {
1274 0 : $dateString = Functions::getDateAsString($date) ." um ".Functions::getTimeAsString($date);
1275 : }
1276 0 : }
1277 1 : $sql = "SELECT DISTINCT ca.*, u.Vorname, u.nachname, u.Email "."FROM calendar_acknowledgement ca "."JOIN user u ON ca.userID = u.ID WHERE ca.eventID = '".Data::toMysql($eventid)."' AND ca.userid IN (SELECT uc.userID FROM calendar_courses cc JOIN user_course uc ON cc.coursesID = uc.courseID WHERE cc.eventID = '".Data::toMysql($eventid)."') "." ORDER BY u.Nachname";
1278 1 : $resultList = $db->get_results($sql, ARRAY_A);
1279 1 : $acceptanceCancellations = "";
1280 1 : if ($resultList != null) {
1281 0 : for ($i = 0 ; $i < count($resultList) ; $i++) {
1282 0 : if ($i%2 == 0) $acceptanceCancellations = $acceptanceCancellations."<tr class='tableCell' valign='top'>";
1283 0 : else $acceptanceCancellations = $acceptanceCancellations."<tr class='tableCellDark' valign='top'>";
1284 0 : $acceptanceCancellations = $acceptanceCancellations."<td style='width: 40%;'>".Data::toHTML($resultList[$i]['nachname']).", ".Data::toHTML($resultList[$i]['Vorname'])."</td>";
1285 0 : if ($resultList[$i]['ack'] == true) {
1286 0 : $acceptanceCancellations = $acceptanceCancellations."<td>Zugesagt</td><td>".Data::toHTML($resultList[$i]['reason'])."</td>";
1287 0 : } else {
1288 0 : $acceptanceCancellations = $acceptanceCancellations."<td>Abgesagt</td><td>".Data::toHTML($resultList[$i]['reason'])."</td>";
1289 : }
1290 0 : $acceptanceCancellations = $acceptanceCancellations."</tr>";
1291 0 : }
1292 0 : }
1293 :
1294 1 : $sql = "SELECT coursesID FROM calendar_courses WHERE eventid = '". Data::toMysql($eventid) ."'";
1295 1 : $resultList = $db->get_results($sql, ARRAY_A);
1296 1 : if ($resultList != null) {
1297 0 : $courseID = $resultList[0]['coursesID'];
1298 0 : }
1299 :
1300 1 : $sql = "SELECT DISTINCT u.Id, u.Vorname, u.nachname, u.Email "."FROM user_course uc "."JOIN user u "."ON u.ID = uc.userID "."WHERE uc.courseID = '".Data::toMysql($courseID)."' "."AND u.id NOT IN (SELECT DISTINCT userID "."FROM calendar_acknowledgement ca "."JOIN user u "."ON ca.userID = u.ID "."WHERE ca.eventID = '".Data::toMysql($eventid)."' "."AND ca.userid IN (SELECT uc.userID FROM calendar_courses cc JOIN user_course uc ON cc.coursesID = uc.courseID WHERE cc.eventID = '".Data::toMysql($eventid)."' )".") ORDER BY u.Nachname";
1301 1 : $resultList = $db->get_results($sql, ARRAY_A);
1302 1 : $notAck = "";
1303 1 : if ($resultList != null) {
1304 0 : for ($i = 0 ; $i < count($resultList) ; $i++) {
1305 0 : if ($i%2 == 0) $notAck = $notAck."<tr class='tableCell' valign='top'>";
1306 0 : else $notAck = $notAck."<tr class='tableCellDark' valign='top'>";
1307 0 : $notAck = $notAck."<td style='width: 40%;'>".Data::toHTML($resultList[$i]['nachname']).", ".Data::toHTML($resultList[$i]['Vorname'])."</td>";
1308 0 : $notAck = $notAck."<td>noch keine Rückmeldung</td>";
1309 0 : $notAck = $notAck."</tr>";
1310 0 : }
1311 0 : }
1312 : //Hilfetexte
1313 1 : $helpAcceptanceCancellation = Utilities::helpCode(130202);
1314 1 : eval($this->templates['eventAcceptanceCancellation']->GetTemplate());
1315 1 : }
1316 : /**
1317 : * Neuen Termin in die DB eintragen
1318 : * @access public
1319 : * @param event Daten fuer den neuen Termin
1320 : */
1321 : public function do_newcevent($event) {
1322 1 : global $db;
1323 1 : $a_errmsg = array();
1324 1 : if (isset($event['kind'])) {
1325 0 : $kindOfEvent = $event['kind'];
1326 0 : } else {
1327 1 : $kindOfEvent = "user";
1328 : }
1329 : // Auf Wunsch einiger Benutzer muss kein Text mehr angegeben werden
1330 1 : if (!isset($event['text'])) $event['text'] = "";
1331 1 : if (!isset($event['subject'])) $a_errmsg[] = 'Sie haben keinen Betreff angegeben.';
1332 1 : if (!isset($event['month'])) $event['month'] = 0;
1333 1 : if (!isset($event['day'])) $event['day'] = 0;
1334 1 : if (!isset($event['year'])) $event['year'] = 0;
1335 1 : if (!isset($event['facultative'])) $event['facultative'] = 0;
1336 0 : else $event['facultative'] = ($event['facultative'] == "0" ? 0 : 1);
1337 : //Uhrzeit und Datum überprüfen
1338 1 : if (!checkdate($event['month'], $event['day'], $event['year'])) $a_errmsg[] = 'Sie haben ein ungültiges Datum angegeben.';
1339 1 : if ($event['hour'] < 0 || $event['hour'] > 23 || $event['minute'] < 0 || $event['minute'] > 59 ) $a_errmsg[] = 'Sie haben eine ungültige Uhrzeit angegeben.';
1340 1 : if (array_count_values($a_errmsg)) {
1341 1 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
1342 1 : Output::errorMessage('Folgende Fehler sind bei der Eingabe aufgetreten:<br/>'.Data::toHTML(implode($a_errmsg, '<br/>')) .'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
1343 1 : echo "</table><br/><br/>";
1344 1 : } else {
1345 1 : if (!isset($event['hour']) || $event['hour'] == '') {
1346 1 : $time = $event['year']."-".$event['month']."-".$event['day']." 00:00:00";
1347 1 : $wholetime = "1";
1348 1 : } else {
1349 0 : if (!isset($event['minute'])) {
1350 0 : $event['minute'] = 0;
1351 0 : $time = $event['year']."-".$event['month']."-".$event['day']." ".$event['hour'].":00:00";
1352 0 : $wholetime = "0";
1353 0 : }
1354 0 : $time = $event['year']."-".$event['month']."-".$event['day']." ".$event['hour'].":".$event['minute'].":00";
1355 0 : $wholetime = "0";
1356 : }
1357 : // Termine innerhalb der Gruppenzeiten?
1358 1 : $kindOfAck = "doNothing";
1359 1 : if ($event['facultative'] == 0) {
1360 : // Art des Termins
1361 1 : if ($kindOfEvent == "course") {
1362 0 : $sql = "SELECT * FROM calendar_frame_courses c JOIN calendar_frame cf ON cf.ID = c.frameID WHERE c.coursesID = '".Data::toMysql($_SESSION['course'])."'";
1363 1 : } else if ($kindOfEvent == "team") {
1364 0 : $sql = "SELECT * FROM calendar_frame_teams c JOIN calendar_frame cf ON cf.ID = c.frameID WHERE c.teamsID = '".Data::toMysql($_SESSION['teamID'])."'";
1365 0 : }
1366 1 : if ($kindOfEvent == "team" || $kindOfEvent == "course") {
1367 0 : $resultList = $db->get_results($sql, ARRAY_A);
1368 0 : if ($resultList != null) {
1369 0 : for ($i = 0 ; $i < count($resultList) ; $i++) {
1370 : // wenn innerhalb der gruppenzeit
1371 0 : if (Calendar::inGrouptime($resultList[$i]['startday'], $resultList[$i]['endday'], $resultList[$i]['starttime'], $resultList[$i]['endtime'], $time, $wholetime)) {
1372 : // alle werden auf zustimmen gesetzt
1373 0 : $kindOfAck = "all";
1374 0 : break;
1375 : }
1376 0 : }
1377 0 : }
1378 0 : }
1379 1 : }
1380 :
1381 : //starte transaktion
1382 1 : $sql = "BEGIN";
1383 1 : Functions::forum_query($sql);
1384 : //fuege kalendereintrag hinzu
1385 1 : $sql = ("INSERT INTO calendar (eventtime,eventsubject,eventtext,eventactive, wholetime ,"."facultative) VALUES ('".Data::toMysql($time)."','".Data::toMysql($event['subject'], false) ."',"."'".Data::toMysql($event['text'], false) ."','1', '".Data::toMysql($wholetime)."',"."'".Data::toMysql($event['facultative'], false) ."');");
1386 1 : Functions::forum_query($sql);
1387 : //hole neue eventid
1388 1 : $neweventid = mysql_insert_id();
1389 1 : if ($kindOfEvent == "user") {
1390 : //fuege datensatz zu calendar_user tabelle hinzu
1391 : $sql = ("INSERT INTO calendar_user (userID,eventID)
1392 1 : VALUES ('".Data::toMysql($_SESSION['userid'])."', '".Data::toMysql($neweventid)."')");
1393 1 : } else if ($kindOfEvent == "course") {
1394 : // fuege Datensatz in calendar_courses hinzu
1395 : $sql = ("INSERT INTO calendar_courses (coursesID,eventID)
1396 0 : VALUES ('".Data::toMysql($_SESSION['course'])."', '".Data::toMysql($neweventid)."')");
1397 0 : } else if ($kindOfEvent == "team") {
1398 : $sql = ("INSERT INTO calendar_teams (teamsID, eventID)
1399 0 : VALUES ('".Data::toMysql($_SESSION['teamID'])."', '".Data::toMysql($neweventid)."')");
1400 0 : }
1401 1 : Functions::forum_query($sql);
1402 : // Fuehre Zustimmung aus
1403 1 : if ($kindOfAck == "all") {
1404 0 : if ($kindOfEvent == "course") {
1405 0 : $eventMembers = Calendar::getEventMembers($_SESSION['course'], $kindOfEvent);
1406 0 : } else if ($kindOfEvent == "team") {
1407 0 : $eventMembers = Calendar::getEventMembers($_SESSION['teamID'], $kindOfEvent);
1408 0 : }
1409 0 : for ($i = 0 ; $i < count($eventMembers) ; $i++) {
1410 : $sql = ("INSERT INTO calendar_acknowledgement (eventID, userID, ack, reason)
1411 0 : VALUES ('".Data::toMysql($neweventid)."', '".Data::toMysql($eventMembers[$i])."', '1', 'Termin wurde automatisch auf akzeptiert gesetzt, da er innerhalb der Gruppenzeit liegt.')");
1412 0 : Functions::forum_query($sql);
1413 0 : }
1414 0 : }
1415 : //beende transaktion
1416 1 : $sql = "COMMIT";
1417 1 : Functions::forum_query($sql);
1418 1 : Functions::message_redirect("Eintrag erfolgreich", "calendar.php?month=".$event['month']."&year=".$event['year']);
1419 1 : if (isset($event['sendmessage']) && isset($kindOfEvent) && $kindOfEvent != '') {
1420 0 : if ($kindOfEvent == "course") { // dem Kurs eine Message schicken
1421 0 : $this->sendGroupMessage($kindOfEvent, $_SESSION['course'], $neweventid, 0, "new", null);
1422 0 : }
1423 0 : if ($kindOfEvent == "team") { // dem Team eine Message schicken
1424 0 : $this->sendGroupMessage($kindOfEvent, $_SESSION['teamID'], $neweventid, 0, "new", null);
1425 0 : }
1426 0 : }
1427 : }
1428 1 : }
1429 : /**
1430 : * Aendert die Rechte zum Eintragen von Kalenderterminen.
1431 : * @access public
1432 : * @param $kind zeigt an, ob die Rechte weggenommen oder zugeteilt werden sollen.
1433 : * @param $userID die ID des Users dessen Rechte geŠndert werden.
1434 : * @param $teamID die ID des Kurses fuer die Rechte geŠndert werden.
1435 : * @param $admin zeigt an, wohin die Weiterleitung zeigen soll.
1436 : * @author Nadja Kruemmel <nadja@kruemmel.info>
1437 : */
1438 : public function editCalendarAuthorization($kind, $userID, $teamID, $admin) {
1439 0 : global $db;
1440 0 : if ($kind == "do") {
1441 0 : mysql_query("UPDATE user_team SET editCalendar='1'
1442 0 : WHERE user_id = '".Data::toMysql($userID)."' AND team_id = '".Data::toMysql($teamID)."'");
1443 0 : if ($admin == "admin") {
1444 0 : Functions::message_redirect("Änderung erfolgreich, User darf nun Teamtermine eintragen.", PATH_TO_ROOT."teams/teamoverview.php");
1445 0 : } else {
1446 0 : Functions::message_redirect("Änderung erfolgreich, User darf nun Teamtermine eintragen.", PATH_TO_ROOT."teams/userteams.php");
1447 : }
1448 0 : } else if ($kind == "not") {
1449 0 : $sql = "SELECT editCalendar FROM user_team WHERE editCalendar = '1' and team_id = '".Data::toMysql($teamID)."'";
1450 0 : $resultList = $db->get_results($sql, ARRAY_A);
1451 0 : if ($resultList != null && count($resultList) > 1) {
1452 0 : mysql_query("UPDATE user_team SET editCalendar='0'
1453 0 : WHERE user_id = '".Data::toMysql($userID)."' AND team_id = '".Data::toMysql($teamID)."'");
1454 0 : if ($admin == "admin") {
1455 0 : Functions::message_redirect("Änderung erfolgreich, User darf nun keine mehr Teamtermine eintragen.", PATH_TO_ROOT."teams/teamoverview.php");
1456 0 : } else {
1457 0 : Functions::message_redirect("Änderung erfolgreich, User darf nun keine mehr Teamtermine eintragen.", PATH_TO_ROOT."teams/userteams.php");
1458 : }
1459 0 : } else {
1460 0 : if ($admin == "admin") {
1461 0 : Functions::message_redirect("Änderung wurden nicht durchgeführt, mindestens ein User muss Teamtermine eintragen dürfen.", PATH_TO_ROOT."teams/teamoverview.php");
1462 0 : } else {
1463 0 : Functions::message_redirect("Änderung wurden nicht durchgeführt, mindestens ein User muss Teamtermine eintragen dürfen.", PATH_TO_ROOT."teams/userteams.php");
1464 : }
1465 : }
1466 0 : }
1467 0 : }
1468 : /**
1469 : * Ueberprueft, ob ein Termin innerhalb der definierten Gruppenezeiten liegt.
1470 : * @access private
1471 : * @param $startDay Anfangstag der Gruppenzeit
1472 : * @param $endDay Endtag der Gruppenzeit
1473 : * @param $startTime Anfangszeit der Gruppenzeit
1474 : * @param $endTime Endzeit der Gruppenzeit
1475 : * @param $eventtime Termin des Events
1476 : * @param $wholetime Ganztages-Termin
1477 : * @author Nadja Kruemmel <nadja@kruemmel.info>
1478 : * @return boolean liefert true, wenn der Termin innerhalb einer Gruppenzeit liegt.
1479 : */
1480 : private static function inGrouptime($startDay, $endDay, $startTime, $endTime, $eventtime, $wholetime) {
1481 0 : if ($wholetime == "0") {
1482 0 : $year = (int)substr($eventtime, 0, 4);
1483 0 : $month = (int)substr($eventtime, 5, 2);
1484 0 : $day = (int)substr($eventtime, 8, 2);
1485 0 : $date = mktime(0, 0, 0, $month, $day, $year);
1486 : // richtiger Wochentag
1487 0 : $dayNumber = date("w", $date);
1488 0 : if($dayNumber == 0) $dayNumber = 7;
1489 0 : if ($dayNumber < $startDay || $dayNumber > $endDay) {
1490 0 : return false;
1491 : }
1492 : // richtige Uhrzeit
1493 0 : $minute = (int)substr($startTime, 3, 2);
1494 0 : $hour = (int)substr($startTime, 0, 2);
1495 0 : $start = mktime($hour, $minute, 0);
1496 0 : $minute = (int)substr($endTime, 3, 2);
1497 0 : $hour = (int)substr($endTime, 0, 2);
1498 0 : $end = mktime($hour, $minute, 0);
1499 0 : $minute = (int)substr($eventtime, 14, 2);
1500 0 : $hour = (int)substr($eventtime, 11, 2);
1501 0 : $time = mktime($hour, $minute, 0);
1502 0 : if ($time < $start || $time > $end) {
1503 0 : return false;
1504 : }
1505 0 : } else if ($wholetime == "1") {
1506 0 : return false;
1507 : }
1508 0 : return true;
1509 : }
1510 : /**
1511 : * Liefert eine Liste mit allen IDs der Gruppenmitglieder.
1512 : * @access private
1513 : * @param $groupID ID der Gruppe
1514 : * @param $kindOfEvent Art des Termins (Team oder Kurs)
1515 : * @author Nadja Kruemmel <nadja@kruemmel.info>
1516 : * @return array mit den IDs der Gruppenmitgliedern
1517 : */
1518 : private static function getEventMembers($groupID, $kindOfEvent) {
1519 0 : global $db;
1520 0 : if ($kindOfEvent == "course") {
1521 0 : $sql = "SELECT userID AS id FROM user_course WHERE courseID = '".Data::toMysql($groupID)."'";
1522 0 : } else if ($kindOfEvent == "team") {
1523 0 : $sql = "SELECT user_id AS id FROM user_team WHERE team_id = '".Data::toMysql($groupID)."'";
1524 0 : }
1525 0 : $resultList = $db->get_results($sql, ARRAY_A);
1526 0 : if ($resultList != null) {
1527 0 : for ($i = 0 ; $i < count($resultList) ; $i++) {
1528 0 : $result[$i] = $resultList[$i]['id'];
1529 0 : }
1530 0 : }
1531 0 : return $result;
1532 : }
1533 : /**
1534 : * Message an die Mitglieder des Kurses/Teams/gesamten Portals (=Foyer -> kindOfEvent="course", groupID=0) senden
1535 : * @access private
1536 : * @param kindOfEvent Gruppentyp ("course" oder "team")
1537 : * @param groupID ID der Gruppe
1538 : * @param id ID des Events
1539 : * @param asEmail 1=auch Mail senden, 0= nur PN
1540 : * @param eventtype Art des Events ("new" oder "edit")
1541 : * @param oldEventtime vorheriger Termin des Events (nur zusammen mit eventtype => bei "edit" wird der Alte Termin und die Änderung geschickt)
1542 : */
1543 : private function sendGroupMessage($kindOfEvent, $groupID, $eventid, $asEmail, $eventtype, $oldEvent) {
1544 0 : $msg = new Messaging($_SESSION["userid"]);
1545 0 : $recipients = '';
1546 0 : $subject = '';
1547 0 : $a_errmsg = array();
1548 : // an einen Kurs, auch fürs Foyer
1549 0 : if ($kindOfEvent == 'course') {
1550 0 : $r_event = Functions::forum_query("SELECT c.* FROM calendar c, calendar_courses co
1551 0 : WHERE c.eventid='".Data::toMysql($eventid)."'
1552 : AND c.eventid=co.eventID
1553 0 : AND co.coursesID='".Data::toMysql($groupID)."'");
1554 0 : $error = mysql_error();
1555 : if($error)
1556 0 : $a_errmsg[] = $error;
1557 : else {
1558 0 : $event = mysql_fetch_array($r_event);
1559 : // Foyer
1560 0 : if ($groupID == 0) {
1561 0 : $r_data = Functions::forum_query("SELECT ID, Vorname, "."Nachname, ShortName, Email FROM user");
1562 0 : $error = mysql_error();
1563 : if($error)
1564 0 : $a_errmsg[] = $error;
1565 : else {
1566 0 : while ($recipient = mysql_fetch_array($r_data)) {
1567 0 : if ($recipient['ID'] == $_SESSION['userid']) continue;
1568 0 : $recipients.= $recipient['Nachname'].", ".$recipient['Vorname'].", ".$recipient['ID']."; ";
1569 0 : }
1570 : }
1571 0 : }
1572 : // Kurs
1573 : else {
1574 0 : $recipientData = Course::getParticipants($groupID);
1575 0 : foreach($recipientData as $recipient) {
1576 0 : if ($recipient->userid == $_SESSION['userid']) continue;
1577 0 : $recipients.= $recipient->lastname.", ".$recipient->firstname.", ".$recipient->userid."; ";
1578 0 : }
1579 : }
1580 : }
1581 0 : }
1582 : // an ein Team
1583 0 : if ($kindOfEvent == 'team') {
1584 0 : $r_event = Functions::forum_query("SELECT c.* FROM calendar c, calendar_teams t
1585 0 : WHERE c.eventid='".Data::toMysql($eventid)."'
1586 : AND c.eventid=t.eventID
1587 0 : AND t.teamsID='".Data::toMysql($groupID)."'");
1588 0 : $error = mysql_error();
1589 : if($error)
1590 0 : $a_errmsg[] = $error;
1591 : else {
1592 0 : $event = mysql_fetch_array($r_event);
1593 0 : $recipientsData = Functions::forum_query("SELECT user.ID, user.Vorname, user.Nachname, user.ShortName, user.Email FROM user LEFT OUTER JOIN user_team ON user.ID=user_team.user_id WHERE user_team.team_id='".Data::toMysql($groupID)."'");
1594 0 : $error = mysql_error();
1595 : if($error)
1596 0 : $a_errmsg[] = $error;
1597 : else {
1598 0 : while ($recipient = mysql_fetch_array($recipientsData)) {
1599 0 : if ($recipient['ID'] == $_SESSION['userid']) continue;
1600 0 : $recipients.= $recipient['Nachname'].", ".$recipient['Vorname'].", ".$recipient['ID']."; ";
1601 0 : }
1602 : }
1603 : }
1604 0 : }
1605 0 : if (array_count_values($a_errmsg)) {
1606 0 : echo "<br/><br/><table width='100%' style='text-align: center;'>";
1607 0 : Output::errorMessage('Folgende Fehler sind aufgetreten:<br/>'.Data::toHTML(implode($a_errmsg, '<br/>')) .'<br/>Gehen Sie mit dem Zurück-Button Ihres Browsers zur vorherigen Seite, um die Angaben zu korrigieren.');
1608 0 : echo "</table><br/><br/>";
1609 0 : }
1610 : else {
1611 0 : if ($eventtype == 'new') {
1612 0 : $subject = "Neuer Termin";
1613 0 : $text = $subject;
1614 0 : }
1615 0 : if ($eventtype == 'edit') {
1616 0 : $subject = "Terminänderung";
1617 0 : $text = $subject.":\nVoriger Termin : am ".Functions::getDateAsString($oldEvent['eventtime']);
1618 0 : if (strlen($oldEvent['eventtime']) == 19) {
1619 0 : $text.= " um ".Functions::getTimeAsString($oldEvent['eventtime']) ." Uhr";
1620 0 : }
1621 0 : $text.= "\nNeuer Termin :";
1622 0 : }
1623 : //Termin wurde bereits gelöscht-> Daten können nicht mehr aus DB gelesen werden
1624 0 : if ($eventtype == 'del') {
1625 0 : $subject = "Termin entfällt";
1626 0 : $text = $subject.":\nDer Termin am ".Functions::getDateAsString($oldEvent['eventtime']);
1627 0 : if ($event['wholetime'] == 0) $text.= " um ".Functions::getTimeAsString($oldEvent['eventtime']) ." Uhr";
1628 0 : $text.= " entfällt";
1629 0 : $subject.= " »".$oldEvent['eventsubject']."«";
1630 0 : } else {
1631 0 : $text.= " am ".Functions::getDateAsString($event['eventtime']);
1632 0 : if ($event['wholetime'] == 0) $text.= " um ".Functions::getTimeAsString($event['eventtime']) ." Uhr";
1633 0 : $text.= "\n\n".$event['eventtext'];
1634 0 : $subject.= " »".$event['eventsubject']."«";
1635 : }
1636 0 : $msg->sendMessage($recipients, $subject, $text, $asEmail);
1637 : }
1638 0 : }
1639 : /**
1640 : * includes the events of this month from the google-calender into $a_events
1641 : * @param $events = googleEvents
1642 : * @param $a_events = eStudyEvents
1643 : * @param $first_day to know, which month and year
1644 : * @param $last_day NotNull, if all events from the beginning of this month have to be taken inside
1645 : */
1646 : private function googleToA_events($a_events, $events, $first_day, $last_day) {
1647 0 : $result = $a_events;
1648 : //einfuegen der google-Termine fuer nur den genannten Monat in $a_events
1649 : //Beginn ab gegebenen $firstday['day']
1650 0 : if($first_day['day'] != NULL) {
1651 0 : foreach($events as $key){
1652 : //einzelne Events auslesen und an entsprechende Tag-Stelle (0-...) in $result schreiben
1653 0 : foreach($key as $key1){
1654 0 : if((strtotime($key1['eventtime']) >= mktime(0, 0, 0, $first_day["month"], $first_day['day'], $first_day['year'])) &&
1655 0 : (strtotime($key1['eventtime']) <= mktime(0, 0, 0, $last_day["month"], $last_day['day'], $last_day['year']))) {
1656 :
1657 0 : $nextEvent = strtotime($key1['eventtime']);
1658 0 : $startDayOfMonth = mktime(0, 0, 0, $first_day["month"], $first_day['day'], $first_day['year']);
1659 0 : $placeInArray = (int)((($nextEvent - $startDayOfMonth)/60)/60/24);
1660 0 : $result[] = $key1;
1661 0 : continue;
1662 : }
1663 : //besondere Behandlung wenn "aktueller Tag" gew�hlt wurde
1664 0 : if(($first_day['day'] == substr($key1['eventtime'], 8, 2)) &&
1665 0 : ($first_day['month'] == substr($key1['eventtime'], 5, 2)) &&
1666 0 : ($first_day['year'] == substr($key1['eventtime'], 0, 4))){
1667 :
1668 0 : $nextEvent = strtotime($key1['eventtime']);
1669 0 : $startDayOfMonth = mktime(0, 0, 0, $first_day["month"], $first_day['day'], $first_day['year']);
1670 0 : $placeInArray = (int)((($nextEvent - $startDayOfMonth)/60)/60/24);
1671 0 : $result[] = $key1;
1672 0 : }
1673 0 : }
1674 0 : }
1675 0 : return $result;
1676 : }
1677 :
1678 : //einfuegen der google-Termine fuer nur den genannten Monat in $a_events
1679 : //Beginn am 1. des Monats
1680 0 : else if($last_day == NULL){
1681 0 : foreach($events as $key){
1682 : //einzelne Events auslesen und an entsprechende Tag-Stelle (0-31) in $result schreiben
1683 0 : foreach($key as $key1){
1684 : //uebergebenen Monat und Jahr pruefen
1685 0 : if($first_day["year"] == date("Y", strtotime($key1['eventtime'])) &&
1686 0 : $first_day["month"] == date("n", strtotime($key1['eventtime']))) {
1687 :
1688 0 : $nextEvent = strtotime($key1['eventtime']);
1689 0 : $firstDayOfMonth = mktime(0, 0, 0, $first_day["month"], 1, $first_day['year']);
1690 0 : $placeInArray = (int)((($nextEvent - $firstDayOfMonth)/60)/60/24);
1691 :
1692 0 : $result[$placeInArray][] = $key1;
1693 0 : }
1694 0 : }
1695 0 : }
1696 : //einfuegen der google-Termine fuer diesen und alle kommenden Monate/Jahre in $a_events
1697 : //benoetigt fuer Anzeige von "naechster Termin"
1698 0 : }else{
1699 0 : foreach($events as $key){
1700 : //einzelne Events auslesen und an entsprechende Tag-Stelle (0-31) in $result schreiben
1701 0 : foreach($key as $key1){
1702 : //uebergebenen Monat und Jahr pruefen
1703 :
1704 0 : $nextEvent = strtotime($key1['eventtime']);
1705 0 : $firstDayOfMonth = mktime(0, 0, 0, $first_day["month"], 1, $first_day['year']);
1706 0 : $placeInArray = (int)((($nextEvent - $firstDayOfMonth)/60)/60/24);
1707 :
1708 0 : $result[$placeInArray][] = $key1;
1709 0 : }
1710 0 : }
1711 : }
1712 0 : return $result;
1713 : }
1714 : }
|